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" in popen(). solve invalid argument, valid arguments w,r, , r+.
  • probably want @ using /usr/sbin/sendmail on modern os x, since there no /usr/lib/sendmail on default install

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -