Postfix 可以接收电子邮件但无法发送

Postfix 可以接收电子邮件但无法发送

我的机器上运行着 postfix(自带 centos minimal),但今天我将其配置为使用我的域名,以便举例说明,这是我的域名example.com。这是我的配置:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
header_checks = regexp:/etc/postfix/header_checks
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
mail_owner = postfix
mailbox_size_limit = 1073741824
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 10485760
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = example.com
myhostname = mail.example.com
mynetworks = 127.0.0.0/8
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = smtp.$mydomain
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_client_restrictions = permit_mynetworks,reject_unknown_client,permit
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
unknown_local_recipient_reject_code = 550

我需要一个电子邮件帐户才能发送电子邮件(密码检索等)。我今天在某处读到,如果您创建 unix 帐户,postfix 会将其识别为电子邮件地址,因此如果您的帐户用户名是,ant您的电子邮件将是[email protected]

因此我进行了测试并尝试发送电子邮件,[email protected]并且成功收到了邮件。

当我尝试使用 ant 任务脚本发送电子邮件时,无法连接:

Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: mail.example.com, port: 25; nested exception is: java.net.ConnectException: Connection timed out: connect 

我在这里遗漏了什么?

编辑

我可以 telnet 到本地主机:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.example.com ESMTP Postfix

答案1

您在某处有一个防火墙,它拒绝与 Postfix 的传入连接。

查看输出:

iptables-save

答案2

您缺少 DNS。mail.example.com必须解析为 127.0.0.1,或者必须将 mail.example.com 的 IP 添加到mynetworks

相关内容