是“linux 中的邮件命令”一劳永逸还是等到邮件发送?
我正在尝试使用以下代码从我的应用程序服务器发送邮件
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);
问题是,我需要分叉一个线程来执行此操作吗?
如果“邮件”命令是“即发即弃”而不是“等待发送”,
我想我不需要为此单独的线程。
我正在使用 MTA 的 postfix。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常不会。
mail
将启动邮件传输代理,将消息交给它,并让它在后台运行。如果您设置了sendwait
选项,它将等待发送。这既适用于使用 MTA(如 sendmail 或 postfix),也适用于直接使用 SMTP(在smtp
选项的影响下)。因此,您需要知道是否设置了
sendwait
选项 - 如果您没有在命令行上设置它,则可以在.mailrc
中设置它,或者作为一个环境变量。如果您想了解更多信息,所有这些都在手册页中进行了更详细的描述。
Not usually.
mail
will start a mail transfer agent, hand it the message, and let it run in the background. If you have thesendwait
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 thesmtp
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.