以前通过 bash 发送邮件可以,现在不行了

以前通过 bash 发送邮件可以,现在不行了

4 个月前,我编写了一个 .sh 脚本,每隔一段时间向自己发送我的 IP 地址,以便能够使用 ssh 远程连接到我的计算机。几个月来我没有使用它,因为我在家工作。我即将再次离开一段时间,所以我将使用它来连接到我的台式电脑,只是,毫无理由,当我运行脚本时,我不再收到邮件,尽管脚本似乎像往常一样运行。我升级了 sendmail-bin 和 mailutils,据我记得(以及从我编写脚本时的 bash 命令历史记录来看),它们就是我当时安装和使用来编写脚本的全部内容。

它很简单,本质上是一个 5 行脚本,如下所示:

#!/bin/bash

echo "O.K."

while true
do
        ip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
        echo "My WAN/Public IP address: ${ip}"
        echo $ip | mail -s "${ip}" [email protected]
        echo "sent"
        sleep 10800
done

当我运行它时,脚本会打印“已发送”,我特意在终端中输入该信息以确认它已被发送。

me@myMacine:~$ ./ipsender.sh
O.K.
My WAN/Public IP address: 111.111.11.111
sent

我甚至还在 gmail 垃圾邮件文件夹中保留了当时使用我的 IP 地址的电子邮件(我以前会将其放入垃圾邮件文件夹中,这对我来说没什么问题,但现在我根本收不到邮件),旧邮件的发送地址中应有我自己的计算机用户名和域名。我真的想不出我做了什么不同的事情,什么都没有;本质上都是一样的,因此想不出它为什么不起作用。我再也收不到任何电子邮件了,这是我所知道的一切。我也尝试过 hotmail.com 地址。

我希望你们能帮助我了解为什么我没有收到电子邮件以及我该怎么做才能解决这个问题。

另外,我已经知道有办法使用我自己的 gmail 地址,使用其他包以及我的 gmail 帐户和密码等。我宁愿继续使用相同的方法并使事情保持简单,再说一次,如果我知道它可以工作,我没有理由改变它;简单就是我的脚本的全部内容。

谢谢。

编辑 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

这是我运行后得到的结果tail -f /var/log/maillog

me@myComputer:~$ sudo tail -f /var/log/mail.log
Jun  4 03:05:10 myComputer sm-mta[9213]: w542YSqo007914: to=<me@myComputer>, delay=05:30:42, xdelay=00:00:00, mailer=local, pri=3000000, dsn=4.0.0, stat=Operating system error
Jun  4 03:05:10 myComputer sm-mta[9230]: w542Vs2b007865: Warning: program /usr/sbin/sensible-mda unsafe: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9230]: w542Vs2b007865: SYSERR(root): Cannot exec /usr/sbin/sensible-mda: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9213]: w542Vs2b007865: to=<me@myComputer>, delay=05:33:16, xdelay=00:00:00, mailer=local, pri=3090000, dsn=4.0.0, stat=Operating system error
Jun  4 03:05:10 myComputer sm-mta[9231]: w542JjVF007748: Warning: program /usr/sbin/sensible-mda unsafe: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9231]: w542JjVF007748: SYSERR(root): Cannot exec /usr/sbin/sensible-mda: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9213]: w542JjVF007748: to=<me@myComputer>, delay=05:45:25, xdelay=00:00:00, mailer=local, pri=3180000, dsn=4.0.0, stat=Operating system error
Jun  4 03:05:10 myComputer sm-mta[9232]: w542B0U6007560: Warning: program /usr/sbin/sensible-mda unsafe: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9232]: w542B0U6007560: SYSERR(root): Cannot exec /usr/sbin/sensible-mda: No such file or directory
Jun  4 03:05:10 myComputer sm-mta[9213]: w542B0U6007560: to=<me@myComputer>, delay=05:54:10, xdelay=00:00:00, mailer=local, pri=3270000, dsn=4.0.0, stat=Operating system error

这是我运行脚本后得到的结果(./ipsender.sh):

Jun  4 03:11:09 myComputer sendmail[9292]: My unqualified host name (myComputer) unknown; sleeping for retry

这里有一个很长的暂停,脚本将处于待命状态。邮件命令完成并从脚本中打印“已发送”后,我在 mail.log 上看到以下内容:

Jun  4 03:12:09 myComputer sendmail[9292]: unable to qualify my own domain name (myComputer) -- using short name
Jun  4 03:12:10 myComputer sendmail[9292]: w548C9EK009292: from=me@myComputer, size=134, class=0, nrcpts=1, msgid=<201806040812.w548C9EK009292@myComputer>, relay=me@localhost
Jun  4 03:12:10 myComputer sm-mta[9303]: w548CAhp009303: from=<me@myComputer>, size=383, class=0, nrcpts=1, msgid=<201806040812.w548C9EK009292@myComputer>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun  4 03:12:10 myComputer sendmail[9292]: w548C9EK009292: to=<[email protected]>, ctladdr=me@myComputer (1000/1000), delay=00:00:01, xdelay=00:00:00, mailer=relay, pri=30134, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w548CAhp009303 Message accepted for delivery)
Jun  4 03:12:10 myComputer sm-mta[9305]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1.2, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jun  4 03:12:10 myComputer sm-mta[9305]: w548CAhp009303: to=<[email protected]>, ctladdr=<me@myComputer> (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120383, relay=gmail-smtp-in.l.google.com. [74.125.198.26], dsn=5.0.0, stat=Service unavailable
Jun  4 03:12:10 myComputer sm-mta[9305]: w548CAhp009303: w548CAhp009305: DSN: Service unavailable
Jun  4 03:12:10 myComputer sm-mta[9307]: w548CAhp009305: Warning: program /usr/sbin/sensible-mda unsafe: No such file or directory
Jun  4 03:12:10 myComputer sm-mta[9307]: w548CAhp009305: SYSERR(root): Cannot exec /usr/sbin/sensible-mda: No such file or directory
Jun  4 03:12:10 myComputer sm-mta[9305]: w548CAhp009305: to=<me@myComputer>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=4.0.0, stat=Operating system error

编辑 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

安装后sensible-mda,的输出tail -f /var/log/mail.log如下(仍然不会收到任何电子邮件):

casillas@DeepNoble:~$ sudo tail -f /var/log/mail.log
Jun  4 03:46:19 DeepNoble sm-mta[11230]: w548kJ5M011230: to=<casillas@DeepNoble>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent
Jun  4 03:47:14 DeepNoble sendmail[11253]: My unqualified host name (DeepNoble) unknown; sleeping for retry
Jun  4 03:48:14 DeepNoble sendmail[11253]: unable to qualify my own domain name (DeepNoble) -- using short name
Jun  4 03:48:14 DeepNoble sendmail[11253]: w548mESn011253: from=casillas@DeepNoble, size=134, class=0, nrcpts=1, msgid=<201806040848.w548mESn011253@DeepNoble>, relay=casillas@localhost
Jun  4 03:48:14 DeepNoble sm-mta[11277]: w548mECQ011277: from=<casillas@DeepNoble>, size=383, class=0, nrcpts=1, msgid=<201806040848.w548mESn011253@DeepNoble>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun  4 03:48:14 DeepNoble sendmail[11253]: w548mESn011253: to=<[email protected]>, ctladdr=casillas@DeepNoble (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30134, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w548mECQ011277 Message accepted for delivery)
Jun  4 03:48:14 DeepNoble sm-mta[11279]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1.2, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jun  4 03:48:14 DeepNoble sm-mta[11279]: w548mECQ011277: to=<[email protected]>, ctladdr=<casillas@DeepNoble> (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=120383, relay=gmail-smtp-in.l.google.com. [173.194.67.26], dsn=5.0.0, stat=Service unavailable
Jun  4 03:48:14 DeepNoble sm-mta[11279]: w548mECQ011277: w548mECQ011279: DSN: Service unavailable
Jun  4 03:48:14 DeepNoble sm-mta[11279]: w548mECQ011279: to=<casillas@DeepNoble>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

运行脚本然后:

Jun  4 03:52:42 DeepNoble sendmail[11335]: My unqualified host name (DeepNoble) unknown; sleeping for retry

长时间停顿,脚本打印“已发送”,然后:

Jun  4 03:53:42 DeepNoble sendmail[11335]: unable to qualify my own domain name (DeepNoble) -- using short name
Jun  4 03:53:42 DeepNoble sendmail[11335]: w548rgKs011335: from=casillas@DeepNoble, size=134, class=0, nrcpts=1, msgid=<201806040853.w548rgKs011335@DeepNoble>, relay=casillas@localhost
Jun  4 03:53:42 DeepNoble sm-mta[11342]: w548rgYu011342: from=<casillas@DeepNoble>, size=383, class=0, nrcpts=1, msgid=<201806040853.w548rgKs011335@DeepNoble>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun  4 03:53:42 DeepNoble sendmail[11335]: w548rgKs011335: to=<[email protected]>, ctladdr=casillas@DeepNoble (1000/1000), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30134, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w548rgYu011342 Message accepted for delivery)
Jun  4 03:53:42 DeepNoble sm-mta[11344]: STARTTLS=client, relay=gmail-smtp-in.l.google.com., version=TLSv1.2, verify=FAIL, cipher=ECDHE-RSA-AES128-GCM-SHA256, bits=128/128
Jun  4 03:53:43 DeepNoble sm-mta[11344]: w548rgYu011342: to=<[email protected]>, ctladdr=<casillas@DeepNoble> (1000/1000), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120383, relay=gmail-smtp-in.l.google.com. [74.125.198.27], dsn=5.0.0, stat=Service unavailable
Jun  4 03:53:43 DeepNoble sm-mta[11344]: w548rgYu011342: w548rhYu011344: DSN: Service unavailable
Jun  4 03:53:43 DeepNoble sm-mta[11344]: w548rhYu011344: to=<casillas@DeepNoble>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

编辑 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

这是我从阅读本地邮件(echo p | mail)中获得的信息,我用“ ”模糊了我当前的 IP 地址+++.+++.++.+++

me@myComputer:~$ echo p | mail
"/var/mail/me": 23 messages 23 new
>N   1 Mail Delivery Subs lun jun  4 03:45  68/2540  Returned mail: see transcript for details
 N   2 Mail Delivery Subs lun jun  4 03:45  64/2674  Returned mail: see transcript for details
 N   3 Mail Delivery Subs lun jun  4 03:45  68/2540  Returned mail: see transcript for details
 N   4 Mail Delivery Subs lun jun  4 03:45  68/2541  Returned mail: see transcript for details
 N   5 Mail Delivery Subs lun jun  4 03:45  68/2541  Returned mail: see transcript for details
 N   6 Mail Delivery Subs lun jun  4 03:45  68/2540  Returned mail: see transcript for details
 N   7 Mail Delivery Subs lun jun  4 03:45  68/2541  Returned mail: see transcript for details
 N   8 Mail Delivery Subs lun jun  4 03:45  68/2542  Returned mail: see transcript for details
 N   9 Mail Delivery Subs lun jun  4 03:45  68/2540  Returned mail: see transcript for details
 N  10 Mail Delivery Subs lun jun  4 03:45  68/2543  Returned mail: see transcript for details
 N  11 Mail Delivery Subs lun jun  4 03:45  68/2517  Returned mail: see transcript for details
 N  12 Mail Delivery Subs lun jun  4 03:45  68/2518  Returned mail: see transcript for details
 N  13 Mail Delivery Subs lun jun  4 03:45  68/2519  Returned mail: see transcript for details
 N  14 Mail Delivery Subs lun jun  4 03:45  68/2519  Returned mail: see transcript for details
 N  15 Mail Delivery Subs lun jun  4 03:45  68/2518  Returned mail: see transcript for details
 N  16 Mail Delivery Subs lun jun  4 03:45  68/2518  Returned mail: see transcript for details
 N  17 Mail Delivery Subs lun jun  4 03:45  64/2651  Returned mail: see transcript for details
 N  18 Mail Delivery Subs lun jun  4 03:45  68/2519  Returned mail: see transcript for details
 N  19 Mail Delivery Subs lun jun  4 03:45  68/2516  Returned mail: see transcript for details
 N  20 Mail Delivery Subs lun jun  4 03:45  68/2519  Returned mail: see transcript for details
 N  21 Mail Delivery Subs lun jun  4 03:46  64/2674  Returned mail: see transcript for details
 N  22 Mail Delivery Subs lun jun  4 03:48  68/2538  Returned mail: see transcript for details
 N  23 Mail Delivery Subs lun jun  4 03:53  68/2540  Returned mail: see transcript for details
Return-Path: <MAILER-DAEMON>
Received: from localhost (localhost)
    by myComputer (8.15.2/8.15.2/Debian-3) id w548GKL8009375;
    Mon, 4 Jun 2018 03:16:20 -0500
Date: Mon, 4 Jun 2018 03:16:20 -0500
From: Mail Delivery Subsystem <MAILER-DAEMON>
Message-Id: <201806040816.w548GKL8009375@myComputer>
To: <me@myComputer>
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
    boundary="w548GKL8009375.1528100180/myComputer"
Subject: Returned mail: see transcript for details
Auto-Submitted: auto-generated (failure)
Content-Length: 1983

This is a MIME-encapsulated message

--w548GKL8009375.1528100180/myComputer

The original message was received at Mon, 4 Jun 2018 03:16:19 -0500
from localhost [127.0.0.1]

   ----- The following addresses had permanent fatal errors -----
<[email protected]>
    (reason: 550-5.7.1 [+++.+++.++.+++] The IP you're using to send mail is not authorized to)

   ----- Transcript of session follows -----
... while talking to gmail-smtp-in.l.google.com.:
>>> DATA
<<< 550-5.7.1 [+++.+++.++.+++] The IP you're using to send mail is not authorized to
<<< 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your
<<< 550-5.7.1 service provider instead. Learn more at
<<< 550 5.7.1  https://support.google.com/mail/?p=NotAuthorizedError q52-v6si5112685otc.25 - gsmtp
554 5.0.0 Service unavailable

--w548GKL8009375.1528100180/myComputer
Content-Type: message/delivery-status

Reporting-MTA: dns; myComputer
Received-From-MTA: DNS; localhost
Arrival-Date: Mon, 4 Jun 2018 03:16:19 -0500

Final-Recipient: RFC822; [email protected]
Action: failed
Status: 5.7.1
Remote-MTA: DNS; gmail-smtp-in.l.google.com
Diagnostic-Code: SMTP; 550-5.7.1 [+++.+++.++.+++] The IP you're using to send mail is not authorized to
Last-Attempt-Date: Mon, 4 Jun 2018 03:16:20 -0500

--w548GKL8009375.1528100180/myComputer
Content-Type: text/rfc822-headers

Return-Path: <me@myComputer>
Received: from myComputer (localhost [127.0.0.1])
    by myComputer (8.15.2/8.15.2/Debian-3) with ESMTP id w548GJL8009373
    for <[email protected]>; Mon, 4 Jun 2018 03:16:19 -0500
Received: (from me@localhost)
    by myComputer (8.15.2/8.15.2/Submit) id w548GJsR009365;
    Mon, 4 Jun 2018 03:16:19 -0500
Date: Mon, 4 Jun 2018 03:16:19 -0500
From: me <me@myComputer>
Message-Id: <201806040816.w548GJsR009365@myComputer>
Subject: regarding the incredibly deadly viper
To: <[email protected]>
X-Mailer: mail (GNU Mailutils 2.99.99)

--w548GKL8009375.1528100180/myComputer--


Saved 1 message in /home/me/mbox
Held 22 messages in /var/mail/me

答案1

<<< 550-5.7.1 [+++.+++.++.+++] The IP you're using to send mail is not authorized to
<<< 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your
<<< 550-5.7.1 service provider instead. Learn more at
<<< 550 5.7.1  https://support.google.com/mail/?p=NotAuthorizedError q52-v6si5112685otc.25 - gsmtp

Google 不再允许您的 IP 直接向其服务器发送邮件。您必须使用 SMTP 中继。

相关内容