![Postfix 别名邮件仅接收来自本地邮箱的邮件](https://linux22.com/image/766986/Postfix%20%E5%88%AB%E5%90%8D%E9%82%AE%E4%BB%B6%E4%BB%85%E6%8E%A5%E6%94%B6%E6%9D%A5%E8%87%AA%E6%9C%AC%E5%9C%B0%E9%82%AE%E7%AE%B1%E7%9A%84%E9%82%AE%E4%BB%B6.png)
我按照指南安装了 Postfix-Dovecot 邮件服务器(如何使用 Postfix、Dovecot 和 MySQL 设置电子邮件服务器) 定义了一个包含虚拟邮箱和映射虚拟域、虚拟用户和虚拟别名的数据库的简单设置。
下面,服务器域名为server.com
。邮件服务器还处理另一个域名,此处称为example.com
。
[email protected]
有一个别名,[email protected]
。以下是发生的事情:
- 邮件发件人
[email protected]
:[email protected]
已发送 - 邮件发件人
[email protected]
:[email protected]
已发送 - 邮寄
[email protected]
至[email protected]
:拒绝
最后一种情况的答复是:
554 5.7.1 <[email protected]>: Recipient address rejected: Unknown user
换句话说,该别名仅从本地邮箱接收消息。
收件人限制如下:
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_recipient,
reject_unknown_recipient_domain,
reject_unlisted_recipient,
reject_unauth_destination,
check_policy_service inet:localhost:12345
答案1
到目前为止,这个问题似乎只被报告过一次这里,在 Dovecot 配额检查中确定了原因。
在这种情况下,这是最后一个smtpd_recipient_restrictions:
check_policy_service inet:localhost:12345
事实上,删除它之后问题就消失了。
当配额检查到位时,日志显示以下内容:
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: auth: master in: USER#0111#[email protected]#011service=quota-status
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]';
dovecot: auth-worker: sql([email protected]): unknown user
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: NOTFOUND#0111
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): auth USER input:
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Userdb lookup failed
postfix/smtpd: NOQUEUE: reject: 554 5.7.1 <[email protected]>: Recipient address rejected: Unknown user; from=<mymailgmail.com> to=<[email protected]>
问题是,定义的查询etc/dovecot/dovecot-sql.conf.ext
仅在表中搜索电子邮件virtual_users
:
query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]';
这Linode 教程上面引用的某个时候指出:
要使用别名作为用户名:
将别名作为源和目标电子邮件地址添加到 virtual_aliases 表中。将
/etc/dovecot/dovecot-sql.conf.ext
文件的 password_query 值更改为:password_query = SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source = '%u');
我选择了一个稍微不同的解决方案,对两个查询进行并集,以便首先搜索虚拟用户,然后搜索虚拟别名:
password_query = SELECT email as user, password FROM virtual_users WHERE email='%u' \
UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source = '%u');
这很好用。以下是日志的摘录:
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: auth: master in: USER#0114#[email protected]#011service=quota-status
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth: sql([email protected]): username changed [email protected] -> [email protected]
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: USER#0114#[email protected]#011uid=5000#011gid=5000#011home=/var/mail/vhosts/example.com/mail
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]' UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source='[email protected]');
dovecot: auth-worker: sql([email protected]): username changed [email protected] -> [email protected]
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): auth USER input: [email protected] uid=5000 gid=5000 home=/var/mail/vhosts/example.com/mail
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Finished userdb lookup
dovecot: quota-status([email protected]): changed username to [email protected]
dovecot: quota-status([email protected]): Effective uid=5000, gid=5000, home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): auth USER input: [email protected] uid=5000 gid=5000 home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): Finished userdb lookup
dovecot: auth: master in: USER#0112#[email protected]#011service=lmtp
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: USER#0112#[email protected]#011uid=5000#011gid=5000#011home=/var/mail/vhosts/example.com/mail
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]' UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source='[email protected]');
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: lmtp([email protected]): lmtp-server: conn unix: rcpt [email protected]: Effective uid=5000, gid=5000, home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): lmtp-server: conn unix: rcpt [email protected]: Mailbox INBOX: Mailbox opened because: lib-lda delivery
dovecot: lmtp([email protected]): saved mail to INBOX
postfix/lmtp: to=<[email protected]>, orig_to=<[email protected]>, relay=server.example.com[private/dovecot-lmtp], status=sent