Postfix

如何使用 dspam 作為後綴和帶有虛擬域的 dovecot 之間的守護程序處理外部別名?

  • September 19, 2015

對於使用 Postfix 2.9.6、DSpam 3.10.1 和 Dovecot 2.1.7 的傳入郵件,我遇到以下情況:

Incoming Mail -> SMTP -> LMTP -> DSpam (as daemon) -> LMTP -> Dovecot

我有帶有虛擬郵箱的虛擬域。到目前為止一切正常。

指向外部域的(虛擬?)別名現在出現了問題。假設,我有以下虛擬域:

virtualdomain1.com
virtualdomain2.com

我正在處理郵件。伺服器本身執行在

mydomain.com

如果我現在添加一個指向外部域的別名,例如:

alias@virtualdomain1.com -> user@externaldomain.com

然後(據我所知),DSpam 檢查郵件,通過 LMTP 將其傳遞給 Dovecot,Dovecot 拒絕郵件,因為 user@externaldomain.com 是未知的(當然是真的)。

那麼如何正確設置才能處理虛擬域的別名呢?如果可能的話,我還想檢查收到的郵件是否有虛擬別名。

alias@virtualdomain1.com 的傳入消息的日誌是:

postfix/smtpd[23910]: connect from xxx.anyhost.com[1.2.3.4]
postfix/smtpd[23910]: NOQUEUE: filter: RCPT from xxx.anyhost.com[1.2.3.4]: <alias@virtualdomain1.com>: Recipient address triggers FILTER lmtp:unix:/dspam/dspam.sock; from=<sender@anyhost.com> to=<alias@virtualdomain1.com> proto=ESMTP helo=<anyhost.com>
postfix/smtpd[23910]: D91D0771AF70: client=xxx.anyhost.com[1.2.3.4]
postfix/cleanup[23917]: D91D0771AF70: message-id=<550937C8.9050901@anyhost.com>
postfix/smtpd[23910]: disconnect from xxx.anyhost.com[1.2.3.4]
postfix/qmgr[23278]: D91D0771AF70: from=<sender@anyhost.com>, size=1030, nrcpt=1 (queue active)
dovecot: lmtp(23920): Debug: none: root=, index=, control=, inbox=, alt=
dovecot: lmtp(23920): Connect from local
dovecot: lmtp(23920): Debug: Loading modules from directory: /usr/lib/dovecot/modules
dovecot: lmtp(23920): Debug: Module loaded: /usr/lib/dovecot/modules/lib90_sieve_plugin.so
dovecot: auth-worker(23921): mysql(127.0.0.1): Connected to database postfixadmin
dspam[9421]: Got error 550 in response to RCPT TO: 550 5.1.1 <user@exampledomain.com> User doesn't exist: user@exampledomain.com#015
dovecot: auth-worker(23921): sql(user@exampledomain.com): unknown user
dovecot: lmtp(23920): Debug: auth input:
dovecot: lmtp(23920): Disconnect from local: Client quit (in RCPT TO)
postfix/lmtp[23918]: D91D0771AF70: to=<user@exampledomain.com>, orig_to=<alias@virtualdomain1.com>, relay=mail.mydomain.com[/dspam/dspam.sock], delay=0.98, delays=0.47/0.01/0/0.5, dsn=5.3.0, status=bounced (host mail.mydomain.com[/dspam/dspam.sock] said: 530 5.3.0 <user@exampledomain.com> Fatal: 550 5.1.1 <user@exampledomain.com> User doesn't exist: user@exampledomain.com (in reply to end of DATA command))
postfix/cleanup[23917]: 149CB771AF72: message-id=<20150318083110.149CB771AF72@mail.mydomain.com>
postfix/bounce[23923]: D91D0771AF70: sender non-delivery notification: 149CB771AF72
postfix/qmgr[23278]: 149CB771AF72: from=<>, size=3182, nrcpt=1 (queue active)
postfix/qmgr[23278]: D91D0771AF70: removed
postfix/smtp[23925]: 149CB771AF72: to=<sender@anyhost.com>, relay=mx.mydomain.com[1.2.3.5]:25, delay=3.9, delays=0.26/0.01/0.09/3.6, dsn=2.0.0, status=sent (250 OK id=1YY9Ne-0007eJ-Hp)
postfix/qmgr[23278]: 149CB771AF72: removed

後綴 main.cf: smtpd_banner = $ myhostname ESMTP $ mail_name (Debian/GNU) biff = no

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

readme_directory = no

# BECAUSE we use Dovecot for authentication we also use its certificates
smtpd_tls_cert_file=/etc/dovecot/dovecot.pem
smtpd_tls_key_file=/etc/dovecot/private/dovecot.pem
smtpd_use_tls=yes
smtpd_tls_auth_only = yes

#Handing off local delivery to Dovecot's LMTP, and telling it where to store mail
virtual_transport = lmtp:unix:private/dovecot-lmtp

#Virtual domains, users, and aliases
virtual_mailbox_domains = proxy:mysql:$config_directory/mysql_virtual_domains_maps.cf
virtual_mailbox_maps =
   proxy:mysql:$config_directory/mysql_virtual_mailbox_maps.cf,
   proxy:mysql:$config_directory/mysql_virtual_alias_domain_mailbox_maps.cf,
   proxy:mysql:$config_directory/mysql_virtual_alias_domain_catchall_maps.cf
virtual_alias_maps =
   proxy:mysql:$config_directory/mysql_virtual_alias_maps.cf,
   proxy:mysql:$config_directory/mysql_virtual_alias_domain_maps.cf
virtual_mailbox_limit = proxy:mysql:$config_directory/mysql_virtual_mailbox_limit_maps.cf

myhostname = mail.me.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost, $myhostname
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 1000000000
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

#Enabling SMTP for authenticated users, and handing off authentication to Dovecot
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions =
       permit_sasl_authenticated,
       permit_mynetworks,
       reject_unauth_destination,
       check_recipient_access pcre:/etc/postfix/dspam_filter_access,
       permit

dspam_filter_access 文件:

/./  FILTER lmtp:unix:/dspam/dspam.sock

最後一點:如果我評論這一行

#check_recipient_access pcre:/etc/postfix/dspam_filter_access,

一切正常,但當然沒有垃圾郵件檢查。

在上述目前設置中,dovecot 和 dspam 都無法將您的電子郵件重新路由到正確的目的地。特別是對於dovecot,它只能接受基於域配置的郵件。

解決方案是在掃描後將您的dspam設置發送回 postfix,而不是將其發送到 dovecot。使用此設置,掃描後綴路由引擎將重新路由您的電子郵件

  • 到外部郵件伺服器,如果收件人地址指向外部域
  • 到 dovecot,如果收件人地址與您的虛擬域匹配

換句話說

[ Outside ] --smtp--> [ Postfix ] --lmtp--> [ dspam ] --smtp--> [ postfix ] --> dovecot (if localdomain) or another mail server (if external domain)

您可以像本教程中的 dspam 設置一樣對其進行配置。步驟總結

  1. 在 master.cf 中添加第二個後綴 smtpd 偵聽器,例如 localhost:10026
  2. 您可以使用 content_filter 參數,而不是使用dspam_filter_access將電子郵件發送到 dspam
  3. **將 DSPAM 中Delivery{Host, Port, Proto}**的配置更改為 postfix second smtpd
  4. 在第二個 smtpd 中禁用地址映射 ( no_address_mappings) content_filter 和另一個限制

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