0

I am trying to send an email in a C program which is only Linux compatible. I am fine with using sendmail to do this as I don't need to read/receive any messages, just send an email every few minutes.

FILE *email = popen("/usr/lib/sendmail -t", "w");
if (email != NULL) {
    fprintf(email, "To: ygvojpqa@guerrillamail.com\r\n");
    fprintf(email, "From: noreply@mydomain.tld\r\n");
    fprintf(email, "Subject: Alert\r\n");
    fprintf(email, "MIME-Version: 1.0\r\n");
    fprintf(email, "Content-Type: text/plain\r\n\r\n");
    fprintf(email, "A fault occured.\r\n");
    if(pclose(email) < 0) {
        std::cout << "pclose fail\n";
        return 1;
    }
} else {
    std::cout << "popen fail\n";
    return 1;
}
return 0;

This code works perfectly as long as there is internet connection and no errors. However, I cannot find a way to see if the email actually went through and was sent successfully. Examply: I unplug my internet and run the snippet above, no error on popen or pclose and it seems like it worked fine, but of course I don't get it because I have no internet.

I'm wondering if there is a way that after I send the email with no errors I can poll something on the linux box to see that the message went through. I am using exim4 as my MTA if that helps. I also look in the exim4 mail queue mailq but it doesn't log any status about the email sent. The only errors it logs is if the TO email is invalid and it freezes it. But when theres no internet there is no code saying that it didn't go through.

Any ideas?

4

0 回答 0