無法從我的 Linux 主機發送電子郵件
無法從我的 Linux 主機發送電子郵件。以下是我嘗試的命令:
echo "This is the message body and contains the message" | sudo mailx -v mypunnq@gmail.com -s "This is the subject"
或者
mail -s "Test Subject" mypunnq@gmail.com < /home/system/mailbody.txt
輸出:
Mail Delivery Status Report will be mailed to <root>.
這是執行過程。
$ ps -ef | grep postfix postfix 2993 30866 0 19:15 ? 00:00:00 pickup -l -t unix -u system 4399 594 0 19:28 pts/0 00:00:00 grep --color=auto postfix root 30866 1 0 2020 ? 00:00:19 /usr/libexec/postfix/master -w postfix 30868 30866 0 2020 ? 00:00:05 qmgr -l -t unix -u
這是顯示埠 25 在我的系統上正在偵聽的 telnet:
$ telnet localhost 25 Trying ::1... Connected to localhost. Escape character is '^]'. 220 efendibey_live.localdomain ESMTP Postfix
這是輸出
mailq
:$ mailq -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- AE3BF1FC5 606 Sun Feb 7 19:15:10 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) mohtashim@digiklug.com 7410B47CA 602 Sun Feb 7 19:18:57 system@efendibey_live.localdomain (delivery temporarily suspended: connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) mypunnq@gmail.com 3EC5F1EC2 474 Sun Feb 7 19:13:34 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) mohtashim@digiklug.com 456251FC6 656 Sun Feb 7 19:18:04 system@efendibey_live.localdomain (connect to mx2.zoho.com[136.143.191.44]:25: Connection timed out) mohtashim@digiklug.com 1CB9D48FB 652 Sun Feb 7 19:20:04 system@efendibey_live.localdomain (connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) mypunnq@gmail.com 1FE9B450F 652 Sun Feb 7 19:19:45 system@efendibey_live.localdomain (connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) mypunnq@gmail.com B180025B5 654 Sun Feb 7 19:25:25 root@efendibey_live.localdomain (delivery temporarily suspended: connect to alt2.gmail-smtp-in.l.google.com[2404:6800:4003:c06::1a]:25: Network is unreachable) mypunnq@gmail.com
更新:
出站埠也打開並連接:
$ telnet gmail-smtp-in.l.google.com 25 Trying 108.177.119.26... Connected to gmail-smtp-in.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP g24si11485107edh.82 - gsmtp
一旦我觸發發送電子郵件的命令,我可以在隊列中看到它
mailQ
然後從隊列中消失,但是,我仍然沒有在我的收件箱中收到郵件。[system@efendibey_live ~]$ echo "This is the message body and contains the message" | sudo mailx -v mohtashim@digiklug.com -s "This is the subject" Mail Delivery Status Report will be mailed to <root>. [system@live ~]$ mailq -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 3723C16BC* 658 Mon Feb 8 13:37:13 root@ebey_live.localdomain mohtashim@digiklug.com -- 1 Kbytes in 1 Request. [system@live ~]$ mailq Mail queue is empty [system@live ~]$
以下是
tail -f /var/log/maillog
單個郵件發送命令的輸出。Feb 8 15:29:43 Efendibey_Live postfix/pickup[10591]: E4F5F16A9: uid=0 from=<root> Feb 8 15:29:43 Efendibey_Live postfix/cleanup[18223]: E4F5F16A9: message-id=<20210208152943.E4F5F16A9@efendibey_live.localdomain> Feb 8 15:29:43 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: from=<root@efendibey_live.localdomain>, size=467, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/smtp[18225]: E4F5F16A9: to=<mohtashim@digiklug.com>, relay=mx.zoho.com[136.143.191.44]:25, delay=1.2, delays=0.03/0.01/0.67/0.51, dsn=5.7.1, status=bounced (host mx.zoho.com[136.143.191.44] said: 541 5.7.1 Mail rejected due to antispam policy (in reply to RCPT TO command)) Feb 8 15:29:45 Efendibey_Live postfix/cleanup[18223]: 468D216BC: message-id=<20210208152945.468D216BC@efendibey_live.localdomain> Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: 468D216BC: from=<>, size=2472, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/bounce[18227]: E4F5F16A9: sender non-delivery notification: 468D216BC Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: removed Feb 8 15:29:45 Efendibey_Live postfix/local[18228]: 468D216BC: to=<root@efendibey_live.localdomain>, relay=local, delay=0.02, delays=0.01/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox) Feb 8 15:29:45 Efendibey_Live postfix/qmgr[1193]: 468D216BC: removed
我什至嘗試了該
-f legitimateemail@gmail.com
選項,mailx
但仍然沒有收到任何電子郵件。這是我的
/etc/hosts
條目# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 127.0.0.1 guest ::1 guest 127.0.0.1 Efendibey_Live ::1 Efendibey_Live
您能否建議我如何從我的 Linux 主機上獲取電子郵件?
在更新中,您顯示您
/var/log/mail.log
包含以下內容:Feb 8 15:29:43 Efendibey_Live postfix/qmgr[1193]: E4F5F16A9: from=<root@efendibey_live.localdomain>, size=467, nrcpt=1 (queue active) Feb 8 15:29:45 Efendibey_Live postfix/smtp[18225]: E4F5F16A9: to=<mohtashim@digiklug.com>, relay=mx.zoho.com[136.143.191.44]:25, delay=1.2, delays=0.03/0.01/0.67/0.51, dsn=5.7.1, status=bounced (host mx.zoho.com[136.143.191.44] said: 541 5.7.1 Mail rejected due to antispam policy (in reply to RCPT TO command))
這意味著您的郵件已成功發送,但被收件人拒絕。地址也很有趣
from=
。看起來您的域是efendibey_live.localdomain
. 如果收件人無法對您的域進行 DNS 查找,那麼他們通常會拒絕您的電子郵件。
postfix
配置後,它使用 的輸出來hostname -f
設置所有內容。這是您的機器名稱和機器的 DNS 條目的函式。解決方案是更新您的/etc/postfix/main.cf
.我的東西看起來像這樣:
$ hostname -f mail.example.com $ cat /etc/hostname mail.example.com $ host -t mx example.com example.com is handled by 10 MAIL.example.com $ host -t a mail.example.com mail.example.com has address aa.bb.cc.dd $ cat /etc/postfix/main.cf | grep myhostname smtpd_banner = $myhostname ESMTP $mail_name myhostname = example.com mydestination = $myhostname, example.com, mail.example.com, localhost.example.com, localhost
這個答案的功勞屬於我最近遇到同樣問題時使用的linuxbabe 。
在您的郵件伺服器上執行以下命令以檢查埠 25(出站)是否被阻止。
telnet gmail-smtp-in.l.google.com 25
如果它沒有被阻止,您會看到如下消息,這表明連接已成功建立。(提示:
quit
輸入並按 Enter 關閉連接。)Trying 74.125.68.26... Connected to gmail-smtp-in.l.google.com. Escape character is '^]'. 220 mx.google.com ESMTP y22si1641751pll.208 - gsmtp
如果埠 25(出站)被阻止,您會看到如下內容:
Trying 2607:f8b0:400e:c06::1a... Trying 74.125.195.27... telnet: Unable to connect to remote host: Connection timed out
在這種情況下,您的 Postfix 無法將電子郵件發送到其他 SMTP 伺服器。請您的 ISP/主機提供商為您打開出站埠 25。如果他們拒絕您的請求,您需要設置 SMTP 中繼以繞過埠 25 阻塞或使用不阻塞埠 25的 VPS(如ScalaHosting )。
有些人可能會問,“我可以將埠 25 更改為另一個埠以繞過阻塞”嗎?答案是不。僅當您同時控制伺服器端和客戶端時,更改埠才有效。當 Postfix 發送電子郵件時,它充當 SMTP 客戶端。收件人的郵件伺服器充當 SMTP 伺服器。您無法控制接收 SMTP 伺服器。SMTP 伺服器正在偵聽埠 25 以接收電子郵件。他們希望 SMTP 客戶端訪問埠 25。沒有其他埠可用於接收電子郵件。如果您的 Postfix 沒有連接到接收 SMTP 伺服器的 25 埠,您將無法發送電子郵件。