我想在每次模拟结束时向我的Gmail帐户发送一封电子邮件。我尝试在网上搜索并发现sendEmail,但超时。如果有人能指出我所尝试的软件包或链接,我将不胜感激。
谢谢
您可以直接使用本地MTA popen()并向其提供符合RFC822的文本。
popen()
#include <stdio.h> #include <string.h> #include <errno.h> int sendmail(const char *to, const char *from, const char *subject, const 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 to invoke sendmail"); } return retval; } main(int argc, char** argv) { int i; printf("argc = %d\n", argc); for (i = 0; i < argc; i++) printf("argv[%d] = \"%s\"\n", i, argv[i]); sendmail(argv[1], argv[2], argv[3], argv[4]); }