我有一个包含 MAILTO=my.email@example.com 的 crontab。我的服务器使用 msmtp 将电子邮件转发到 Amazon Simple Email Service。我的问题是 cron 命令的输出永远不会到达我的邮箱。这是 msmtp 日志所说的内容:
Mar 06 14:26:02 host=email-smtp.us-east-1.amazonaws.com tls=on auth=on user=MY.SES.USER from=my.email@example.com recipients=my.email@example.com smtpstatus=554 smtpmsg='554 Transaction failed: User name is missing: ?Cron Daemon ?.' errormsg='the server did not accept the mail' exitcode=EX_UNAVAILABLE
我需要做什么才能使 Amazon SES 接受 cron 电子邮件?
最佳答案
建议的解决方案来自 AWS Developer Forums :
It turns out that cron has the "from" address hard-coded in the source (q.v. "do_command.c" in the cron source), so one does not have influence over what cron transmits to sendmail (which in our case is symlinked to "/usr/bin/msmtp").
However, due to the magic of Linux, we do have the ability to alter the stream of text that goes into sendmail.
The way I worked around this cron limitation was to move the "msmtp" binary to"msmtp.bin" and then create "/usr/bin/msmtp" that was a shell script:
#! /bin/bash sed -e 's/root .Cron Daemon./user@example.com/' | /usr/bin/msmtp.bin "$@"
This is also, AFAIK, the only means one has to set the "debug" flag to msmtp when used in a "global" setting (such as cron, or other cases where sendmail is invoked with arguments you don't control).
While the script above is rather simplistic, you can also conditionally alter the text by checking the input arguments for the magic "-FCronDaemon" which is also hard coded in the cron binary. I would be stunned if any other program calls sendmail with "-FCronDaemon".
关于amazon-web-services - 通过 msmtp 发送 Crontab 电子邮件 -> Amazon SES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15250199/