Postfix

CentOs/Dovecot/Postfix 沒有收到來自外部的電子郵件

  • July 24, 2017

我正在嘗試設置我的郵件伺服器,但我在使用 Postfix 時遇到了一些問題。特別是我無法接收來自外部的電子郵件。

這是我的 /etc/postfix/main.cf 的內容

readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
myhostname = mail.paolo9785.com
mydomain = paolo9785.com
relay_host = paolo9785.com
myorigin = paolo9785.com
home_mailbox = mail/
mynetworks = 127.0.0.0/8
inet_interfaces = all
inet_protocols = all
inet_interfaces = localhost
mydestination = mail.paolo9785.com, localhost.paolo9785.com, localhost, paolo9785.com
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_key_file = /etc/postfix/ssl/server.key
smtpd_tls_cert_file = /etc/postfix/ssl/server.crt
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

message_size_limit = 30720000
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
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


smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service,
check_policy_service  = unix:private/policy
policy_time_limit = 3600

#DKIM config

smtpd_milters           = inet:127.0.0.1:8891, inet:127.0.0.1:8893
non_smtpd_milters       = $smtpd_milters
milter_default_action   = accept
milter_protocol         = 2

這是我的master.cf

cat /etc/postfix/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       -       n       -       -       smtpd

submission     inet  n       -       n       -       -       smtpd
     -o syslog_name=postfix/submission
     -o smtpd_sasl_auth_enable=yes
     -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
     -o milter_macro_daemon_name=ORIGINATING
   smtps     inet  n       -       n       -       -       smtpd
     -o syslog_name=postfix/smtps
     -o smtpd_sasl_auth_enable=yes
     -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
     -o milter_macro_daemon_name=ORIGINATING

#smtp      inet  n       -       n       -       1       postscreen
#smtpd     pass  -       -       n       -       -       smtpd
#dnsblog   unix  -       -       n       -       0       dnsblog
#tlsproxy  unix  -       -       n       -       0       tlsproxy
#submission inet n       -       n       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       n       -       -       smtpd
#  -o syslog_name=postfix/smtps
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
#  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       n       -       -       qmqpd
pickup    unix  n       -       n       60      1       pickup
cleanup   unix  n       -       n       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
#qmgr     unix  n       -       n       300     1       oqmgr
tlsmgr    unix  -       -       n       1000?   1       tlsmgr
rewrite   unix  -       -       n       -       -       trivial-rewrite
bounce    unix  -       -       n       -       0       bounce
defer     unix  -       -       n       -       0       bounce
trace     unix  -       -       n       -       0       bounce
verify    unix  -       -       n       -       1       verify
flush     unix  n       -       n       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       n       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       n       -       -       showq
error     unix  -       -       n       -       -       error
retry     unix  -       -       n       -       -       error
discard   unix  -       -       n       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil
scache    unix  -       -       n       -       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/local/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=/usr/lib/cyrus-imapd/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
#
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/usr/lib/cyrus-imapd/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/local/sbin/bsmtp -f $sender $nexthop $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/libexec/dovecot/deliver -f ${sender} -d ${recipient}

policy unix - n n - 0 spawn user=nobody argv=/bin/python /usr/libexec/postfix/policyd-spf

目前有一個使用者集(info@…)。

systemctl status postfix -l
● postfix.service - Postfix Mail Transport Agent
  Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
  Active: active (running) since Mon 2017-07-24 21:53:04 CEST; 15min ago
 Process: 6591 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS)
 Process: 6650 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
 Process: 6644 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
 Process: 6632 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
Main PID: 6972 (master)
  CGroup: /system.slice/postfix.service
          ├─ 1751 tlsmgr -l -t unix -u
          ├─ 6972 /usr/libexec/postfix/master -w
          ├─ 6981 pickup -l -t unix -u
          ├─ 6982 qmgr -l -t unix -u
          ├─20770 smtpd -n smtp -t inet -u -o stress= -s 2
          ├─20776 proxymap -t unix -u
          ├─20804 anvil -l -t unix -u
          ├─21475 trivial-rewrite -n rewrite -t unix -u
          ├─21750 cleanup -z -t unix -u
          └─21778 local -t unix

Jul 24 22:07:23 mail.paolo9785.com postfix/trivial-rewrite[21475]: warning: do not list domain paolo9785.com in BOTH mydestination and virtual_mailbox_domains
Jul 24 22:07:23 mail.paolo9785.com postfix/smtpd[20770]: warning: restriction check_policy_service must be followed by transport:server
Jul 24 22:07:23 mail.paolo9785.com postfix/smtpd[20770]: NOQUEUE: reject: RCPT from mail-ua0-f181.google.com[209.85.217.181]: 451 4.3.5 Server configuration error; from=<XXXXXXXX@gmail.com> to=<root@paolo9785.com> proto=ESMTP helo=<mail-ua0-f181.google.com>
Jul 24 22:07:23 mail.paolo9785.com postfix/cleanup[21750]: 9C4A85EE6A: message-id=<20170724200723.9C4A85EE6A@mail.paolo9785.com>
Jul 24 22:07:23 mail.paolo9785.com postfix/qmgr[6982]: 9C4A85EE6A: from=<double-bounce@mail.paolo9785.com>, size=1382, nrcpt=1 (queue active)
Jul 24 22:07:23 mail.paolo9785.com postfix/smtpd[20770]: disconnect from mail-ua0-f181.google.com[209.85.217.181]
Jul 24 22:07:23 mail.paolo9785.com postfix/trivial-rewrite[21475]: warning: do not list domain paolo9785.com in BOTH mydestination and virtual_mailbox_domains
Jul 24 22:07:23 mail.paolo9785.com postfix/trivial-rewrite[21475]: warning: do not list domain paolo9785.com in BOTH mydestination and virtual_mailbox_domains
Jul 24 22:07:23 mail.paolo9785.com postfix/local[21778]: 9C4A85EE6A: to=<root@paolo9785.com>, orig_to=<postmaster>, relay=local, delay=0.01, delays=0.01/0/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Jul 24 22:07:23 mail.paolo9785.com postfix/qmgr[6982]: 9C4A85EE6A: removed

systemctl status dovecot -l
● dovecot.service - Dovecot IMAP/POP3 email server
  Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; vendor preset: disabled)
  Active: active (running) since Mon 2017-07-24 20:49:26 CEST; 1h 28min ago
Main PID: 24904 (dovecot)
  CGroup: /system.slice/dovecot.service
          ├─ 2108 dovecot/imap-login
          ├─ 2500 dovecot/imap
          ├─24904 /usr/sbin/dovecot -F
          ├─24927 dovecot/anvil
          ├─24928 dovecot/log
          ├─24932 dovecot/config
          ├─29697 dovecot/auth
          ├─30635 dovecot/imap-login
          └─32508 dovecot/imap

Jul 24 21:58:03 mail.paolo9785.com dovecot[24928]: pop3-login: Login: user=<info@paolo9785.com>, method=PLAIN, rip=5.102.9.124, lip=164.132.225.73, mpid=9533, TLS, session=<adD1oRVVZAAFZgl8>
Jul 24 21:58:04 mail.paolo9785.com dovecot[24928]: pop3(info@paolo9785.com): Disconnected: Logged out top=0/0, retr=0/0, del=0/1, size=737
Jul 24 22:08:34 mail.paolo9785.com dovecot[24928]: pop3-login: Login: user=<info@paolo9785.com>, method=PLAIN, rip=5.102.9.124, lip=164.132.225.73, mpid=18393, TLS, session=<PfCKxxVVnAAFZgl8>
Jul 24 22:08:35 mail.paolo9785.com dovecot[24928]: pop3(info@paolo9785.com): Disconnected: Logged out top=0/0, retr=0/0, del=0/1, size=737
Jul 24 22:15:02 mail.paolo9785.com dovecot[24928]: pop3-login: Login: user=<info@paolo9785.com>, method=PLAIN, rip=5.102.9.124, lip=164.132.225.73, mpid=22021, TLS, session=<txmt3hVVqwAFZgl8>
Jul 24 22:15:03 mail.paolo9785.com dovecot[24928]: pop3(info@paolo9785.com): Disconnected: Logged out top=0/0, retr=0/0, del=0/1, size=737
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

所有埠都在防火牆上打開:

firewall-cmd --list-all
public (active)
 target: default
 icmp-block-inversion: no
 interfaces: eth0
 sources:
 services: dhcpv6-client http https imaps pop3s smtp ssh
 ports: 110/tcp 465/tcp 587/tcp 25/tcp 143/tcp 3306/tcp 9000/tcp 993/tcp
 protocols:
 masquerade: no
 forward-ports:
 sourceports:
 icmp-blocks:
 rich rules:

其他配置文件的內容包括:

cat /etc/postfix/mysql-virtual_forwardings.cf
user = mail_admin
password = ******************
dbname = mail
query = SELECT destination FROM forwardings WHERE source='%s'
hosts = 127.0.0.1

cat /etc/postfix/mysql-virtual_email2email.cf
user = mail_admin
password = **********
dbname = mail
query = SELECT email FROM users WHERE email='%s'
hosts = 127.0.0.1

cat /etc/postfix/mysql-virtual_domains.cf
user = mail_admin
password = **********
dbname = mail
query = SELECT domain AS virtual FROM domains WHERE domain='%s'
hosts = 127.0.0.1

cat /etc/postfix/mysql-virtual_mailboxes.cf
user = mail_admin
password = ****************
dbname = mail
query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email='%s'
hosts = 127.0.0.1

有什麼建議嗎?MX 記錄似乎是正確的,在日誌中我也可以看到我的電子郵件已到達伺服器但未成功處理。正如您在日誌中看到的那樣,我正在嘗試從我的 gmail 發送電子郵件。

提前感謝您的寶貴幫助:-)

我在配置中看到至少一個錯誤:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service, check_policy_service = unix:private/policy

check_policy_service 參數應立即跟隨它,而不是指定為單獨的選項:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination, check_policy_service unix:private/policy

將它們全部放在一行上,並且在check_policy_serviceand之間沒有’=’unix:private/policy

引用自:https://serverfault.com/questions/864919