What I am trying to do, is have my c program execute a function that uses the system() function with mailx. When I output the variable that holds the const *char that the system() function needs it looks fine. But I do not get the email. Yet when I run the mailx command via CLI, I get the email. Here is my code: Thank you in advance
#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;
}