You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu环境下Postfix/Dovecot无法接收外部邮件的排查与解决求助

Ubuntu环境下Postfix/Dovecot无法接收外部邮件的排查与解决求助

各位大佬好,我最近搭建了基于Postfix和Dovecot的邮件服务器,折腾了好几天还是卡在一个问题上,翻遍相关讨论线程都没找到头绪,想请大家帮忙分析下!

目前的情况是:

  • 可以正常发送邮件
  • 能接收来自localhost和同域其他邮箱的邮件
  • 完全收不到Gmail这类外部邮箱发来的邮件,发送方后台显示邮件已送达,但我的服务器里完全看不到相关邮件的踪迹,所有发送和认证流程看起来都是正常的。

下面是我的Dovecot和Postfix配置信息:

Dovecot配置(sudo doveconf -n输出)

# 2.3.14 (cee3cbc0d): /etc/dovecot/dovecot.conf
# Pigeonhole version 0.5.14 (1b5c82b2)
# OS: Linux 4.15.0-29-generic x86_64 Ubuntu 18.04.5 LTS
# Hostname: nameofthehost

auth_mechanisms = plain login
dict {
  sqlquota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
first_valid_uid = 5000
last_valid_uid = 5000
mail_gid = vmail
mail_location = mbox:~/mail:INBOX=/var/mail/%u
mail_plugins = quota
mail_privileged_group = vmail
mail_uid = vmail
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate mime foreverypart extracttext imapsieve vnd.dovecot.imapsieve

namespace inbox {
  inbox = yes
  location =
  mailbox Drafts {
    special_use = \Drafts
  }
  mailbox Junk {
    special_use = \Junk
  }
  mailbox Sent {
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    special_use = \Sent
  }
  mailbox Spam {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Trash {
    special_use = \Trash
  }
  prefix =
}

passdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}

plugin {
  imapsieve_mailbox1_before = file:/var/mail/vmail/sieve/global/report-spam.sieve
  imapsieve_mailbox1_causes = COPY
  imapsieve_mailbox1_name = Spam
  imapsieve_mailbox2_before = file:/var/mail/vmail/sieve/global/report-ham.sieve
  imapsieve_mailbox2_causes = COPY
  imapsieve_mailbox2_from = Spam
  imapsieve_mailbox2_name = *
  quota = dict:User quota::proxy::sqlquota
  quota_exceeded_message = Quota exceeded, please contact your system administrator.
  quota_grace = 10%%
  quota_rule = *:storage=5GB
  quota_rule2 = Trash:storage=+100M
  quota_warning = storage=100%% quota-warning 100 %u
  quota_warning2 = storage=95%% quota-warning 95 %u
  quota_warning3 = storage=90%% quota-warning 90 %u
  quota_warning4 = storage=85%% quota-warning 85 %u
  sieve = file:/var/mail/vmail/sieve/%d/%n/scripts;active=/var/mail/vmail/sieve/%d/%n/active-script.sieve
  sieve_before = /var/mail/vmail/sieve/global/spam-global.sieve
  sieve_global_extensions = +vnd.dovecot.pipe
  sieve_pipe_bin_dir = /usr/bin
  sieve_plugins = sieve_imapsieve sieve_extprograms
}

protocols = " imap lmtp sieve pop3"

service auth-worker {
  user = vmail
}

service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0666
    user = postfix
  }
  unix_listener auth-userdb {
    group = vmail
    mode = 0600
    user = vmail
  }
}

service dict {
  unix_listener dict {
    group = vmail
    mode = 0660
    user = vmail
  }
}

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0600
    user = postfix
  }
}

service managesieve-login {
  inet_listener sieve {
    port = 4190
  }
}

service managesieve {
  process_limit = 1024
}

service quota-warning {
  executable = script /usr/local/bin/quota-warning.sh
  unix_listener quota-warning {
    group = vmail
    mode = 0660
    user = vmail
  }
  user = vmail
}

ssl_cert = </etc/letsencrypt/live/mydomain.com/fullchain.pem
ssl_cipher_list = EECDH+AES:EDH+AES+aRSA
ssl_dh = # hidden, use -P to show it
ssl_key = # hidden, use -P to show it
ssl_prefer_server_ciphers = yes

userdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}

protocol lmtp {
  mail_plugins = quota sieve
  postmaster_address = postmaster@mydomain.com
}

protocol imap {
  mail_plugins = quota imap_quota imap_sieve
}

Postfix配置(postconf -n输出)

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = yes
compatibility_level = 2
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
milter_default_action = accept
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
milter_protocol = 6
mydestination = localhost.$mydomain, localhost, $mydomain
myhostname = nameofthehost
myorigin = /etc/mailname
non_smtpd_milters = inet:127.0.0.1:11332
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_note_starttls_offer = yes
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_milters = inet:127.0.0.1:11332
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_tls_cert_file = /etc/letsencrypt/live/mydomain.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mydomain.com/privkey.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = no
virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp

更新信息

我用Gmail发测试邮件,Gmail后台显示邮件已送达:

Message ID CALJ3QLOrZD5GhaaaFiXO5xZp+=sjSa1+PF5w=DBgozHB5qEu3A@mail.gmail.com
Created on: 18 May 2023 at 11:16 (Delivered after 0 seconds)

但查看服务器的mail.log,完全找不到这封邮件的接收记录,日志内容如下:

May 18 11:15:39 3b15 dovecot: imap-login: Login: user=<contact@mydomain.com>, method=PLAIN, rip=::1, lip=::1, mpid=4319, secured, session=<8kXxaPP7Yt4AAAAAAAAAAAAAAAAAAAAB>
May 18 11:15:39 3b15 dovecot: imap(contact@mydomain.com)<4319><8kXxaPP7Yt4AAAAAAAAAAAAAAAAAAAAB>: Logged out in=90 out=972 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
May 18 11:16:41 3b15 dovecot: imap-login: Login: user=<contact@mydomain.com>, method=PLAIN, rip=::1, lip=::1, mpid=4331, secured, session=<hkGZbPP7dN4AAAAAAAAAAAAAAAAAAAAB>
May 18 11:16:41 3b15 dovecot: imap(contact@mydomain.com)<4331><hkGZbPP7dN4AAAAAAAAAAAAAAAAAAAAB>: Logged out in=90 out=972 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
May 18 11:17:23 3b15 postfix/anvil[4241]: statistics: max connection rate 1/60s for (smtps:212.83.8.79) at May 18 11:14:03
May 18 11:17:23 3b15 postfix/anvil[4241]: statistics: max connection count 1 for (smtps:212.83.8.79) at May 18 11:14:03
May 18 11:17:23 3b15 postfix/anvil[4241]: statistics: max cache size 1 at May 18 11:14:03
May 18 11:17:39 3b15 dovecot: imap-login: Login: user=<contact@mydomain.com>, method=PLAIN, rip=::1, lip=::1, mpid=4402, secured, session=<OsMWcPP7it4AAAAAAAAAAAAAAAAAAAAB>
May 18 11:17:39 3b15 dovecot: imap(contact@mydomain.com)<4402><OsMWcPP7it4AAAAAAAAAAAAAAAAAAAAB>: Logged out in=90 out=972 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
May 18 11:18:01 3b15 postfix/pickup[4122]: 8D50342261: uid=33 from=<www-data>
May 18 11:18:01 3b15 postfix/cleanup[4411]: 8D50342261: message-id=<20230518081801.8D50342261@som.time4vps.cloud>
May 18 11:18:01 3b15 postfix/qmgr[4123]: 8D50342261: from=<www-data@3som.time4vps.cloud>, size=745, nrcpt=1 (queue active)
May 18 11:18:01 3b15 postfix/smtp[4413]: 8D50342261: to=<www-data@som.time4vps.cloud>, orig_to=<www-data>, relay=none, delay=0.09, delays=0.06/0.03/0.01/0, dsn=5.4.6, status=bounced (mail for som.time4vps.cloud loops back to myself)
May 18 11:18:01 3b15 postfix/cleanup[4411]: A04B742262: message-id=<20230518081801.A04B742262@som.time4vps.cloud>
May 18 11:18:01 3b15 postfix/qmgr[4123]: A04B742262: from=<>, size=3524, nrcpt=1 (queue active)
May 18 11:18:01 3b15 postfix/bounce[4414]: 8D50342261: sender non-delivery notification: A04B742262
May 18 11:18:01 3b15 postfix/qmgr[4123]: 8D50342261: removed
May 18 11:18:01 3b15 postfix/smtp[4413]: A04B742262: to=<www-data@som.time4vps.cloud>, relay=none, delay=0.01, delays=0.01/0/0/0, dsn=5.4.6, status=bounced (mail for som.time4vps.cloud loops back to myself)
May 18 11:18:01 3b15 postfix/qmgr[4123]: A04B742262: removed

我尝试修改过mydestination = localhost.$mydomain, localhost, mail.$mydomain, $mydomain,但还是没有效果。

想请教大家:我该怎么调试这个问题?怎么才能让服务器正常接收外部邮件呢?

备注:内容来源于stack exchange,提问作者Don40

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 13:23:04