我正在尝试编写一个bash脚本,由cron任务运行,在某些情况下会向我发送电子邮件。
为了尝试让sendmail使用我的Sendgrid SMTP设置,我使用以下内容编辑了 /etc/postfix/main.cf 文件:
smtp_sasl_password_maps = static:<username>:<password>
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
smtp_tls_security_level=encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
我使用 sudo /etc/init.d/postfix restart重启后缀
尝试使用以下命令从命令行发送电子邮件:
sendmail my@email.com&lt; /tmp/email.txt
这导致以下输出:
您在/ var / mail / ubuntu
中有新邮件
为什么sendgrid不使用我在main.cf中指定的Sendgrid SMTP详细信息发送电子邮件?
请注意,此问题仅与sendmail有关,我不想安装其他SMTP客户端和应用程序,它需要按原样运行。
答案 0 :(得分:10)
我的Postfix配置错误。我需要使用以下内容:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:<username>:<password>
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
通过bash脚本发送电子邮件的方式如下:
sendmail email@address.com <<EOF
subject:This is a test
from:from@address.com
Body message here...
EOF