我遇到了一个问题,即 gmail 阻止了使用 mailx 发送的电子邮件。我通过设置一个合适的 ~/.mailrc 解决了这个问题,它看起来像:
set smtp-use-starttls
set nss-config-dir=/home/theuser/.certs
set ssl-verify=ignore
set smtp=smtp://smtp.gmail.com:587
set smtp-auth=login
set smtp-auth-user=xxx
set smtp-auth-password=yyy
set from="rabbitovh@thehologram.com(Rabbit Server)"
Run Code Online (Sandbox Code Playgroud)
所以现在当我运行时:
echo "hi" | mailx xxx@gmail.com
Run Code Online (Sandbox Code Playgroud)
我的电子邮件以用户和 root 身份成功发送。
现在我希望 cron 也能工作。我更改了“/etc/sysconfig/crond”以强制它使用mailx,使用:
CRONDARGS="-m /usr/bin/mailx"
Run Code Online (Sandbox Code Playgroud)
我有 ~/.mailrc 设置:
但无论我做什么,echo 输出都没有成功通过电子邮件发送。
crontab 看起来像(我已经检查过,脚本正在运行并完成它们的工作,并且回显,只是 cron 不发送电子邮件):
MAILTO="xxx@gmail.com"
# Every minute check processes are running, restart if necessary and send an email.
* * * * * source /home/theuser/.bashrc; global audit_regular
# Every day, send an email …
Run Code Online (Sandbox Code Playgroud)