1
问题: 未能调用的sendmail:无效的参数使用MTA在Mac OS X中使用c程序发送电子邮件。
#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;
}
我tryed使用C程序发送电子邮件蒙山的Mac OS X中的代码。我不知道问题出在哪里(在代码或本地MTA中)。有人可以给出建议该怎么做?