I’m trying to send mail from my application server using the following code
FILE *mailer = popen("/usr/bin/mail -s 'Some subject here' user@domain", "w");
fprintf(mailer, "Hello %s,\nThis note is to inform you that your job completed successfully.\n", username);
pclose(mailer);
Question is, would I need to fork a thread to do this?
if the ‘mail’ command is ‘fire-and-forget’ opposed to ‘wait-till-sent’,
I guess I don’t need a separate thread for this.
I’m using postfix for MTA.
Not usually.
mailwill start a mail transfer agent, hand it the message, and let it run in the background. If you have thesendwaitoption set, it will wait for it to be sent. That applies both when using an MTA, like sendmail or postfix, and when using SMTP directly (under the influence of thesmtpoption).So, you need to know if the
sendwaitoption is set – if you’re not setting it on the command line, then it could be set in.mailrc, or as an environment variable.All this is described in marginally more detail in the man page, if you want to know more.