Advertisement
paulogp

Envia email usando o comando "sendmail"

Jul 13th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. // Apple Xcode
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. // unix, linux
  8. #define SENDMAIL "/usr/sbin/sendmail -t"
  9.  
  10.  
  11. int main (int argc, const char * argv[])
  12. {
  13.     // send email using comand sendmail
  14.     char *the_to = "To:bla@bla.bla\n";
  15.     //char *the_from = "From:bla@bla.bla\n";
  16.  
  17.     FILE *the_email;
  18.  
  19.     if ((the_email = popen(SENDMAIL, "w")))
  20.     {
  21.         // to
  22.         fputs(the_to, the_email);
  23.  
  24.         // from
  25.         //fputs(the_from, the_email);
  26.  
  27.         // subject
  28.         fputs("Subject: My Subject!\n\n", the_email);
  29.  
  30.         // message
  31.         fputs("Hello World!\n", the_email);
  32.  
  33.         // close
  34.         pclose(the_email);
  35.     }
  36.     else
  37.     {
  38.         puts("erro no envio de email");
  39.     }
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement