Postfix - 无法外部访问

Postfix - 无法外部访问

所以我似乎无法从外部访问 smtp。当使用桌面电子邮件客户端(eM 客户端和 thunderbird 都失败)时,我根本无法让它访问服务器。(eM 客户端正在尝试访问:smtp://[电子邮件保护]:25 如果有帮助的话)

我通过 nmap 查看了,看起来端口 25 对所有人都开放。

另外,我尝试从另一台服务器进行 telnet,但出现以下错误:

554 5.7.1 <[email protected]>: Relay access denied

这是我的 postconf -n:

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
config_directory = /etc/postfix
delay_warning_time = 4h
disable_vrfy_command = yes
inet_interfaces = all
local_recipient_maps =
maximal_backoff_time = 8000s
maximal_queue_lifetime = 7d
message_size_limit = 30720000
minimal_backoff_time = 1000s
mydestination =
mynetworks = 127.0.0.0/8
myorigin = /etc/mailname
readme_directory = /usr/share/doc/postfix
relayhost =
smtp_helo_timeout = 60s
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_client_restrictions = reject_rbl_client sbl.spamhaus.org, reject_rbl_client blackholes.easynet.nl, reject_rbl_client dnsbl.njabl.org
smtpd_data_restrictions = reject_unauth_pipelining
smtpd_delay_reject = yes
smtpd_hard_error_limit = 12
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_hostname, reject_invalid_hostname, permit
smtpd_recipient_limit = 16
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, permit
smtpd_sender_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
smtpd_soft_error_limit = 3
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 450
virtual_alias_maps = mysql:/etc/postfix/mysql_alias.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /var/spool/mail/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_mailbox.cf
virtual_uid_maps = static:5000

这是我的 main.cf 文件:

# 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
#myorigin=xxxx.com

# This is already done in /etc/mailname
#myhostname = xxxx.xxxx.com

smtpd_banner = $myhostname ESMTP $mail_name
#biff = no


# appending .domain is the MUA's job.
#append_dot_mydomain = no

readme_directory = /usr/share/doc/postfix

# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.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.

# Relay smtp through another server or leave blank to do it yourself
#relayhost = smtp.yourisp.com

# Network details; Accept connections from anywhere, and only trust this machine
mynetworks = 127.0.0.0/8
inet_interfaces = all
#mynetworks_style = host

# Masquerade emails aka convert [email protected] to [email protected]
# !sub.domain.com means not to masquerade
#masquerade_domains = xxxx.com
#masquerade_exceptions = root

#As we will be using virtual domains, these need to be empty
local_recipient_maps =
mydestination =

# how long if undelivered before sending "delayed mail" warning update to sender
delay_warning_time = 4h
# will it be a permanent error or temporary
unknown_local_recipient_reject_code = 450
# how long to keep message on queue before return as failed.
# some have 3 days, I have 16 days as I am backup server for some people
# whom go on holiday with their server switched off.
maximal_queue_lifetime = 7d
# max and min time in seconds between retries if connection failed
minimal_backoff_time = 1000s
maximal_backoff_time = 8000s
# how long to wait when servers connect before receiving rest of data
smtp_helo_timeout = 60s
# how many address can be used in one message.
# effective stopper to mass spammers, accidental copy in whole address list
# but may restrict intentional mail shots.
smtpd_recipient_limit = 16
# how many error before back off.
smtpd_soft_error_limit = 3
# how many max errors before blocking it.
smtpd_hard_error_limit = 12


# Requirements for the HELO statement
smtpd_helo_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_hostname, reject_invalid_hostname, permit
# Requirements for the sender details
smtpd_sender_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit
# Requirements for the connecting server
smtpd_client_restrictions = reject_rbl_client sbl.spamhaus.org, reject_rbl_client blackholes.easynet.nl, reject_rbl_client dnsbl.njabl.org
# Requirement for the recipient address
smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, permit
smtpd_data_restrictions = reject_unauth_pipelining
# require proper helo at connections
smtpd_helo_required = yes
# waste spammers time before rejecting them
smtpd_delay_reject = yes
disable_vrfy_command = yes

# not sure of the difference of the next two
# but they are needed for local aliasing
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
# this specifies where the virtual mailbox folders will be located
virtual_mailbox_base = /var/spool/mail/vmail
# this is for the mailbox location for each user
virtual_mailbox_maps = mysql:/etc/postfix/mysql_mailbox.cf
# and this is for aliases
virtual_alias_maps = mysql:/etc/postfix/mysql_alias.cf
# and this is for domain lookups
virtual_mailbox_domains = mysql:/etc/postfix/mysql_domains.cf
# this is how to connect to the domains (all virtual, but the option is there)
# not used yet
# transport_maps = mysql:/etc/postfix/mysql_transport.cf

# Setup the uid/gid of the owner of the mail files - static:5000 allows virtual ones
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

#######################
## OLD CONFIGURATION ##
#######################
#myorigin = /etc/mailname
#mydestination = xxxx.xxxx.com, localhost, localhost.localdomain
#mailbox_size_limit = 0
#recipient_delimiter = +
#html_directory = /usr/share/doc/postfix/html
message_size_limit = 30720000
#virtual_alias_domains =
##virtual_alias_maps = hash:/etc/postfix/virtual
#virtual_mailbox_base = /home/vmail
##luser_relay = webmaster
#smtpd_sasl_type = dovecot
#smtpd_sasl_path = private/auth
#smtpd_sasl_auth_enable = yes
#smtpd_sasl_security_options = noanonymous
#broken_sasl_auth_clients = yes
#smtpd_sasl_authenticated_header = yes
#smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
#virtual_create_maildirsize = yes
#virtual_maildir_extended = yes
#proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
#virtual_transport = dovecot
#dovecot_destination_recipient_limit = 1

另外,这是我的 master.cf

#
# Postfix master process configuration file.  For details on the format
# of the file, see the master(5) manual page (command: "man 5 master").
#
# Do not forget to execute "postfix reload" after editing this file.
#
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
smtp      inet  n       -       -       -       -       smtpd
#submission inet n       -       -       -       -       smtpd
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       -       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       -       -       -       qmqpd
pickup    fifo  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
#qmgr     fifo  n       -       -       300     1       oqmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay     unix  -       -       -       -       -       smtp
        -o smtp_fallback_relay=
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
#
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
#
# ====================================================================
#
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
#
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
#
# ====================================================================
#
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}
dovecot   unix  -       n       n       -       -       pipe
    flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}

我以前用过 dovecot,但已经改用 courier 了。Courier 似乎运行正常(我能够正确使用 imap),但只有 SMTP 出现故障。奇怪的是,我可以通过 telnet 从服务器本身发送 SMTP 电子邮件,但只有当我尝试从另一台服务器 telnet 进入服务器或尝试通过桌面电子邮件客户端发送电子邮件时才会失败。(尽管我已通过 iptables 启用日志记录,但桌面客户端甚至没有在 syslog 中注册)

我对邮件服务器不太熟悉,所以我不知道该问什么。我尝试更改 main.cf 中的某些中继参数,但似乎没有任何改变。此外,由于某种原因,我仍然无法让我的邮件客户端正确访问我的服务器,尽管之前我为 dovecot 设置了参数后它就可以正常工作(这些参数仍然保留在 main.cf 中,但已被注释掉)

tl;dr 为什么当我尝试从外部服务器发送电子邮件时,会出现中继访问被拒绝的情况?另外,为什么我无法通过桌面电子邮件客户端访问 smtp?

任何额外信息均可根据需要/请求随时提供

提前致谢。

答案1

您的 SMTP 服务似乎运行良好。

您的问题是,您尝试从端口 25 上的 MUA 发送电子邮件,这是一个馊主意即使你能以某种方式让它工作。

你需要启用submission部分n 在您的 postfix 中master.cf,然后将您的电子邮件客户端配置为在端口 587 而不是 25 上发送。

答案2

如果您的桌面客户端位于家庭网络上,则您的 ISP 很有可能禁止端口 25 上的出站连接。如果您的连接尝试被 ISP 阻止,这就可以解释为什么您在服务器上看不到它们的证据。

正如迈克尔·汉普顿所说,您可以submission在端口 587 上启用该服务。我还建议设置 SSL,并且最好设置出站邮件的身份验证。

关于中继错误:您尚未smtpd_relay_restrictions在配置中设置,这意味着您使用的是默认值permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination。这意味着,除非您使用用户名和密码向服务器进行身份验证,否则 Postfix 将拒绝电子邮件,除非:

  • 客户端 IP 地址与 $mynetworks 中列出的任何网络或网络地址匹配。
  • Postfix 是邮件转发器:解析后的 RCPT TO 域与 $relay_domains 或其子域匹配,并且不包含发件人指定的路由(user@elsewhere@domain),
  • Postfix 是最终目的地:解析的 RCPT TO 域与 $mydestination、$inet_interfaces、$proxy_interfaces、$virtual_alias_domains 或 $virtual_mailbox_domains 匹配,并且不包含发件人指定的路由(user@elsewhere@domain)。

这是来自:http://www.postfix.org/SMTPD_ACCESS_README.html(以及相关配置文档)。

相关内容