【问题标题】:Email not Sent Using Shell cmd/script on Centos在 Centos 上未使用 Shell cmd/脚本发送电子邮件
【发布时间】:2018-11-01 14:47:11
【问题描述】:

我正在尝试使用 shell cmd 从我的 centos 向我的 gmail 地址发送一封电子邮件。

这是我所做的配置:

/etc/postfix/main.cf

myhostname = relay.example.com
relayhost = [smtp.gmail.com]:587
mailbox_size_limit = 0
recipient_delimiter = +
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous 

/etc/postfix/sasl_passwd

[smtp.gmail.com]:587 My_Address@gmail.com:My_Password

我为 Postfix 创建了 hash db 文件:

postmap /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

我在重启 Postfix 后运行 cmd:

echo "Body" | mail -s "Subject" My_Address@gmail.com

我将 gmail 设置为可以接受不太安全的应用程序。

请注意,我没有网络问题(如下图所示):

1st Connectivity Test 2nd Connectivity Test

运行cmd后没有报错,但是没有发送消息。

查看日志:tail -f /var/log/maillog

Nov  2 00:55:43 quickstart sendmail[5228]: wA1JwGn3031205: to=<My_Address@gmail.com>, ctladdr=<cloudera@quickstart.cloudera> (501/501), delay=11:56:47, xdelay=00:00:00, mailer=esmtp, pri=390482, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Nov  2 00:55:43 quickstart sendmail[5228]: wA1JchlC026214: to=<My_Address@gmail.com>, ctladdr=<cloudera@quickstart.cloudera> (501/501), delay=12:16:44, xdelay=00:00:00, mailer=esmtp, pri=480482, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Nov  2 00:55:43 quickstart sendmail[5228]: wA1JCSq5019689: to=<My_Address@gmail.com>, ctladdr=<cloudera@quickstart.cloudera> (501/501), delay=12:42:59, xdelay=00:00:00, mailer=esmtp, pri=480482, relay=alt4.gmail-smtp-in.l.google.com., dsn=4.0.0, stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
Nov  2 01:17:17 quickstart postfix/postfix-script[8412]: fatal: the Postfix mail system is not running
Nov  2 01:17:17 quickstart postfix/postfix-script[8469]: warning: group or other writable: /etc/postfix/./main.cf
Nov  2 01:17:17 quickstart postfix/postfix-script[8483]: starting the Postfix mail system
Nov  2 01:17:17 quickstart postfix/master[8484]: fatal: bind 127.0.0.1 port 25: Address already in use
Nov  2 01:18:14 quickstart sendmail[8554]: wA28IEGk008554: from=cloudera, size=228, class=0, nrcpts=1, msgid=<201811020818.wA28IEGk008554@quickstart.cloudera>, relay=root@localhost
Nov  2 01:18:14 quickstart sendmail[8558]: wA28IEsc008558: from=<cloudera@quickstart.cloudera>, size=483, class=0, nrcpts=1, msgid=<201811020818.wA28IEGk008554@quickstart.cloudera>, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Nov  2 01:18:14 quickstart sendmail[8554]: wA28IEGk008554: to=My_Addressq@gmail.com, ctladdr=cloudera (501/501), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30228, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (wA28IEsc008558 Message accepted for delivery)

您能帮忙吗,谢谢!

【问题讨论】:

  • 请发布显示错误的后缀日志。
  • 抱歉回复晚了!我刚刚添加了一个 Maillog 视图。如果这是你要求的?
  • Google 不会接受来自地址是 localhost 的地方,因为您的后缀服务器没有将真实域附加到用户。
  • 您能否重新检查一下我刚刚发布的 Maillog 的(新)视图。 (前一个不是相关的)。我的错!
  • Postfix 没有运行,因为端口 25 上正在运行其他东西。运行 lsof | egrep -i "25|SMTP" 这应该会告诉您端口 25 上的内容。可能是 sendmail。但是最后一行表明 google 接受了来自 sendmail 的消息。

标签: email centos smtp sh postfix-mta


【解决方案1】:

我了解到您的网络没有问题。邮件发送脚本需要做一些小的改动。请遵循以下格式,如果可行,请告诉我

echo "Body" | mail -s "Subject" -m My_Address@gmail.com

【讨论】:

  • 感谢您的反应,它已经开始工作了。我在回答中添加了一些细节。
【解决方案2】:

问题是 Sendmail 也被安装了,这是另一个邮件服务器。因此,Postfix 自动被禁用,因为它们中的两个不能同时运行。

这是来自日志的致命错误:tail -f /var/log/maillog

Nov  2 01:17:17 quickstart postfix/postfix-script[8412]: fatal: the Postfix mail system is not running

我通过完全删除 sendmail 解决了这个问题

[root@quickstart ~]# yum remove sendmail

然后重启 Postfix

[root@quickstart ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-19
    • 2012-09-12
    • 2012-05-07
    • 2013-05-17
    • 2016-05-05
    • 2014-10-25
    • 2011-09-16
    • 2020-11-03
    相关资源
    最近更新 更多