amazon-web-services - 通过 msmtp 发送 Crontab 电子邮件 -> Amazon SES

标签 amazon-web-services cron smtp crontab amazon-ses

我有一个包含 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/

相关文章:

bash - shell脚本每天用时间戳创建文件夹并推送时间戳生成的日志

linux - 如何在 crontab 中提供密码

IIS SMTP 消息检查

python - 无法通过 Python 从 Ubuntu 上的 Gmail 发送电子邮件

amazon-web-services - AWS SNS - 如何获取由发布者 lambda 输出触发的订阅者 lambda

amazon-web-services - AWS : Difference between User data and Metadata tags when creating EC2 instance

amazon-web-services - SQS 过期 token : The security token included in the request is expired status code:

linux - Crontab 无法运行我的 Perl 模块

启用 SSL 后 Apache James 未收到来自外部发件人的电子邮件

linux - 允许 RTMP 流到 AWS?