我想要做的是让我的c程序执行一个函数,该函数使用mailx的system()函数。当我输出保存system()函数所需的const * char的变量时,它看起来很好。但我没有收到电子邮件。然而,当我通过CLI运行mailx命令时,我收到了电子邮件。这是我的代码:提前谢谢
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void send_email(char *to_who, char *subject, char *message)
{
char command[1024];
char command_buffer[1024];
if (snprintf(command_buffer, sizeof(command_buffer), "echo \"%s\" | mailx -s \"%s\" %s", message, subject, to_who) >= sizeof(command_buffer))
{
printf("Command Buffer Overload");
}
strcpy(command, command_buffer);
system(command);
//Check to see command contents
printf("%s", command);
}
int main ()
{
send_email("user@email.com","C Email Test", "Test Email with C");
return 0;
}