开发者

is "mail command in linux" fire-and-forget or wait-until-mail-sent?

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. mail will start a mail transfer agent, hand it the message, and let it run in the background. If you have the sendwait option 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 the smtp option).

So, you need to know if the sendwait option 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜