问题:调用 sendmail 失败:参数无效
编码
#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 to 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;
}
我尝试使用 c 程序通过 Mac OS X 发送电子邮件。我不知道问题出在哪里(在代码中或在本地 MTA 中)。有人可以给点建议吗?