/* * mail.h * * Created on: Feb 13, 2015 * Author: Paul Bunt * Code modified from a answer provided at * http://stackoverflow.com/questions/2362989/how-can-i-send-e-mail-in-c */ #ifndef MAIL_H_ #define MAIL_H_ #include #include #include int send_mail(char to[], char body[]){ char cmd[100]; // to hold the command. char tempFile[100]; // name of tempfile. strcpy(tempFile,tempnam("/tmp","sendmail")); // generate temp file name. FILE *fp = fopen(tempFile,"w"); // open it for writing. fprintf(fp,"%s\n",body); // write body to it. fclose(fp); // close it. sprintf(cmd,"sendmail %s < %s",to,tempFile); // prepare command. system(cmd); // execute it. return 0; } #endif /* MAIL_H_ */