使用bash / ubuntu发送电子邮件

时间:2016-09-12 06:13:07

标签: bash shell email ubuntu smtp

所以我试着编写一个相当简单的脚本,其中一部分是发送电子邮件。问题是脚本运行没有任何错误,一切正常,但我从来没有收到那封电子邮件。我相信一些gmail弹出窗口应该会成功,但我也不会这样做。完成本教程:https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/但问题仍然存在。有什么想法,可以在这做什么?

我尝试过测试并从终端窗口发送电子邮件 - 同样的事情

main.cf文件相关的唯一警告是 "warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost =" 即使脚本今天只运行了两次,也有大量的内容。 main.cf文件中的第42行是"relayhost = [smtp.gmail.com]:587"

我使用的脚本中的行是

`mail -s "Subject" -A "info.$NOW.log" my@email.com`

日志: Sep 12 09:59:55 shroomz-VirtualBox postfix/qmgr[5372]: 3D892636CF: from=<shroomz@shroomz-VirtualBox>, size=370, nrcpt=1 (queue active) Sep 12 09:59:55 shroomz-VirtualBox postfix/trivial-rewrite[5481]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 09:59:55 shroomz-VirtualBox postfix/smtp[5482]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 09:59:55 shroomz-VirtualBox postfix/tlsmgr[5483]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/sendmail[5486]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/postdrop[5487]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/cleanup[5488]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/pickup[5371]: 865D06267A: uid=1000 from=<shroomz@shroomz-VirtualBox> Sep 12 10:00:03 shroomz-VirtualBox postfix/cleanup[5488]: 865D06267A: message-id=<20160912070003.865D06267A@shroomz-VirtualBox.lt.emea.csc.com> Sep 12 10:00:03 shroomz-VirtualBox postfix/qmgr[5372]: 865D06267A: from=<shroomz@shroomz-VirtualBox>, size=399, nrcpt=1 (queue active) Sep 12 10:00:03 shroomz-VirtualBox postfix/local[5489]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/bounce[5490]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/local[5489]: 865D06267A: to=<sarunas.petkevicius@gmail.com>, relay=local, delay=0.04, delays=0.02/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "sarunas.petkevicius") Sep 12 10:00:03 shroomz-VirtualBox postfix/cleanup[5488]: 8DBE26267C: message-id=<20160912070003.8DBE26267C@shroomz-VirtualBox.lt.emea.csc.com> Sep 12 10:00:03 shroomz-VirtualBox postfix/bounce[5491]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:03 shroomz-VirtualBox postfix/qmgr[5372]: 8DBE26267C: from=<>, size=2406, nrcpt=1 (queue active) Sep 12 10:00:03 shroomz-VirtualBox postfix/bounce[5490]: 865D06267A: sender non-delivery notification: 8DBE26267C Sep 12 10:00:03 shroomz-VirtualBox postfix/qmgr[5372]: 865D06267A: removed Sep 12 10:00:03 shroomz-VirtualBox postfix/local[5489]: 8DBE26267C: to=<shroomz@shroomz-VirtualBox>, relay=local, delay=0.01, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox) Sep 12 10:00:03 shroomz-VirtualBox postfix/qmgr[5372]: 8DBE26267C: removed Sep 12 10:00:25 shroomz-VirtualBox postfix/smtp[5482]: connect to smtp.gmail.com[74.125.206.108]:587: Connection timed out Sep 12 10:00:25 shroomz-VirtualBox postfix/smtp[5482]: connect to smtp.gmail.com[2a00:1450:400c:c04::6c]:587: Network is unreachable Sep 12 10:00:55 shroomz-VirtualBox postfix/smtp[5482]: connect to smtp.gmail.com[74.125.206.109]:587: Connection timed out Sep 12 10:00:55 shroomz-VirtualBox postfix/bounce[5494]: warning: /etc/postfix/main.cf, line 42: overriding earlier entry: relayhost= Sep 12 10:00:55 shroomz-VirtualBox postfix/smtp[5482]: 3D892636CF: to=<user@domain.com>, relay=none, delay=229326, delays=229266/0.06/60/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[74.125.206.109]:587: Connection timed out)

2 个答案:

答案 0 :(得分:0)

问题在于您的网络配置,您需要检查以下内容:

telnet smtp.gmail.com 587

这可能会产生Unable to connect to remote host: Connection timed out

检查您的互联网连接,防火墙规则可能会阻止587上的传出TCP以及您使用ip route list的路由表。

答案 1 :(得分:0)

echo "your text " | mail -s subject your@mail.com

并且您必须配置从主机发送的电子邮件,无论您有exim还是后缀。