osx - Send email with c program in Mac OS X using MTA. -
the problem: failed invoke sendmail: invalid argument
the code
#include<stdio.h> #include<errno.h> #include<string.h> int add(char* to,char* from,char* subject,char* message) { int retval = -1; file *mailpipe = popen("/usr/lib/sendmail -t", "w+"); if (mailpipe != null) { fprintf(mailpipe, "to: %s\n", to); fprintf(mailpipe, "from: %s\n", from); fprintf(mailpipe, "subject: %s\n\n", subject); fwrite(message, 1, strlen(message), mailpipe); fwrite(".\n", 1, 2, mailpipe); pclose(mailpipe); retval = 0; } else { perror("failed invoke sendmail"); } return retval; } int main() { char to1[256]; char from1[256]; char message1[256]; char sub1[256]; int i; printf("hello\n"); scanf("%s",to1); scanf("%s",from1); scanf("%s",message1); scanf("%s",sub1); i=add(to1, from1, sub1, message1); return 0; }
i tryed send email whith mac os x using c program. dont know problem is(in code or in local mta). can give advice do?
there's definite bug , probable one:
- definitely need change
"w+"
"w"
inpopen()
. solve invalid argument, valid argumentsw
,r
, ,r+
. - probably want @ using
/usr/sbin/sendmail
on modern os x, since there no/usr/lib/sendmail
on default install
Comments
Post a Comment