无法从我的 Linux 主机发送电子邮件。下面是我尝试的命令:
echo "This is the message body and contains the message" | sudo mailx -v [email protected] -s "This is the subject"
或者
mail -s "Test Subject" [email protected] < /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)
[email protected]
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)
[email protected]
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)
[email protected]
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)
[email protected]
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)
[email protected]
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)
[email protected]
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)
[email protected]
更新:
出站端口也打开并正在连接:
$ 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 [email protected] -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
[email protected]
-- 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=<[email protected]>, 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 [email protected]
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 主机接收电子邮件?
答案1
这个答案的功劳属于linux宝贝我最近遇到同样问题时使用过。
在邮件服务器上运行以下命令检查端口 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 阻塞或使用 VPS,例如Scala托管这不会阻塞端口 25。
有些人可能会问,“我可以将端口 25 更改为其他端口以绕过阻塞吗”?答案是不。仅当您同时控制服务器端和客户端时,更改端口才有效。当 Postfix 发送电子邮件时,它充当 SMTP 客户端。收件人的邮件服务器充当 SMTP 服务器。您无法控制接收 SMTP 服务器。 SMTP 服务器正在侦听端口 25 以接收电子邮件。他们期望 SMTP 客户端访问端口 25。没有其他端口可用于接收电子邮件。如果您的 Postfix 未连接到接收 SMTP 服务器的端口 25,您将无法发送电子邮件。
答案2
在更新中,您展示了您/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=<[email protected]>,
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