在 Centos 上使用 Shell cmd/script 未发送电子邮件
Email not Sent Using Shell cmd/script on Centos
我正在尝试使用 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 创建了哈希数据库文件:
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)
能不能帮帮忙,谢谢!
问题是还安装了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 ]
我了解到您的网络没有问题。邮件发送脚本需要做一些小改动。请按照以下格式,如果有效请告诉我
echo "Body" | mail -s "Subject" -m My_Address@gmail.com
我正在尝试使用 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 创建了哈希数据库文件:
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)
能不能帮帮忙,谢谢!
问题是还安装了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 ]
我了解到您的网络没有问题。邮件发送脚本需要做一些小改动。请按照以下格式,如果有效请告诉我
echo "Body" | mail -s "Subject" -m My_Address@gmail.com