我正在尝试配置我的 Amazon EC2 实例以使用 postfix 接收电子邮件。我尝试了几个小时,但从未收到电子邮件。如果我从同一服务器终端发送电子邮件,它就可以正常工作。这是有效的
echo "My message" | mail -s subject [email protected]
但是如果我尝试从外部发送电子邮件(例如 gmail),我收不到。我的端口 25 是开放的。我也没有收到任何投递失败的消息。在 postfix 日志中也找不到任何相关问题。如果有人能帮助我找出问题所在,我将不胜感激。
这是我的 postfix 配置文件。
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = example.com
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
alias_maps = hash:/etc/aliases
正如 Alex 所建议的,swaks 输出如下。
=== Trying 52.62.94.158:25...
=== Connected to 52.62.94.158.
<- 220 example.com ESMTP Postfix (Ubuntu)
-> EHLO ip-172-31-21-89.ap-southeast-2.compute.internal
<- 250-example.com
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-VRFY
<- 250-ETRN
<- 250-STARTTLS
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250 DSN
-> MAIL FROM:<[email protected]>
<- 250 2.1.0 Ok
-> RCPT TO:<[email protected]>
<- 250 2.1.5 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> Date: Sat, 12 Mar 2016 23:08:43 +1100
-> To: [email protected]
-> From: [email protected]
-> Subject: Test
-> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
->
-> This is a test mailing
->
-> .
<- 250 2.0.0 Ok: queued as E44EE642AD
-> QUIT
<- 221 2.0.0 Bye
我收到了那封邮件。然后我又试着从我的 Gmail 发送电子邮件。不幸的是,它失败了。当我尝试检查我的[电子邮件保护]来自此处的电子邮件。上面写着“糟糕”http://verify-email.org/
答案1
您的 MX 记录指向名称smtp.example.com
,但是该名称没有任何地址记录。
$ host example.com
example.com has address 52.62.94.158
example.com mail is handled by 10 smtp.example.com.
$ host smtp.example.com
Host smtp.example.com not found: 3(NXDOMAIN)
因此,您域名的邮件无法投递。
答案2
只需添加第二个解决方案,它完全是疏忽,类似于您使用 MX 的解决方案。我能够将电子邮件从服务器发送出去,以及发送到同一服务器上的其他虚拟域。但我无法从服务器外部接收任何内容,但能够从其他虚拟域接收。
我只是忘了启用防火墙。
sudo ufw allow Postfix
sudo ufw enable
sudo ufw status
希望它将来能够对某些人有所帮助。