我按照本教程使用虚拟用户(在 mysql 数据库中)配置 Postfix + Dovecot:https://www.digitalocean.com/community/tutorials/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassasin
我可以创建一个用户(在数据库中添加一行),然后该用户可以连接到电子邮件客户端(使用 IMAP)。问题是该用户无法接收电子邮件(我尝试将电子邮件从一个用户发送到另一个用户,因此是本地电子邮件)。
我已经创建了 2 个用户和,bla
以及salut
域名isp6.lab
(我在主机 mail.isp6.lab 中添加了 127.0.0.1,从这边进行本地测试没有问题)。
/var/log/mail.log 如下所示:
Oct 5 13:43:28 debianR postfix/lmtp[6346]: 4284485120: to=<[email protected]>, relay=mail.isp6.lab[private/dovecot-lmtp], delay=0.12, delays=0.08/0/0/0.04, dsn=5.1.1, status=bounced (host mail.isp6.lab[private/dovecot-lmtp] said: 550 5.1.1 <[email protected]> User doesn't exist: [email protected] (in reply to RCPT TO command))
在我的 /etc/dovecot/conf.d/10-mail.conf 中,mail_location 有以下一行:
mail_location = maildir:/var/mail/vhosts/%d/%n
在我的 /etc/dovecot/conf.d/auth-sql-conf.ext 中(只是一个示例,不是完整文件):
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
}
当我转到 /var/mail/vhosts/isp6.lab 时,我会看到我的两个用户的文件夹如下:
ls /var/mail/vhosts/isp6.lab
bla
salut
因此,我的用户可以登录,他们在系统上有他们的电子邮件文件夹,但不知何故他们无法收到任何电子邮件,因为它们“不存在”。
如果需要的话,请随时向我询问其他信息,我已经找遍了所有地方,但找不到问题的原因。
编辑 :调试日志提供了更多信息:
当发送电子邮件至bla
时salut
:
Oct 05 15:12:22 auth: Debug: auth client connected (pid=0)
Oct 05 15:12:22 auth: Debug: client in: AUTH 1 LOGIN service=smtp nologin lip=192.168.1.2 rip=192.168.1.3 secured
Oct 05 15:12:22 auth: Debug: client out: CONT 1 VXNlcm5hbWU6
Oct 05 15:12:22 auth: Debug: client in: CONT 1 YmxhQGlzcDYubGFi
Oct 05 15:12:22 auth: Debug: client out: CONT 1 UGFzc3dvcmQ6
Oct 05 15:12:22 auth: Debug: client in: CONT 1 YmxhYmxh
Oct 05 15:12:22 auth-worker(7448): Debug: sql([email protected],192.168.1.3): query: SELECT NULL AS password, 'Y' as nopassword, email AS user FROM accounts WHERE email = '[email protected]' AND pass = password('***********')
Oct 05 15:12:22 auth: Debug: client out: OK 1 [email protected]
Oct 05 15:12:22 lmtp(7467): Debug: none: root=, index=, control=, inbox=, alt=
Oct 05 15:12:22 lmtp(7467): Info: Connect from local
Oct 05 15:12:22 auth: Debug: master in: USER 1 [email protected] service=lmtp
Oct 05 15:12:22 auth-worker(7448): Debug: sql([email protected]): query: SELECT NULL AS password, 'Y' as nopassword, email AS user FROM accounts WHERE email = '[email protected]' AND pass = password('')
Oct 05 15:12:22 auth-worker(7448): Info: sql([email protected]): unknown user
Oct 05 15:12:22 auth: Debug: master out: NOTFOUND 1
Oct 05 15:12:22 lmtp(7467): Debug: auth input:
Oct 05 15:12:22 lmtp(7467): Info: Disconnect from local: Client quit (in reset)
Oct 05 15:12:22 lmtp(7467): Debug: none: root=, index=, control=, inbox=, alt=
Oct 05 15:12:22 lmtp(7467): Info: Connect from local
Oct 05 15:12:22 auth: Debug: master in: USER 2 [email protected] service=lmtp
Oct 05 15:12:22 auth-worker(7448): Debug: sql([email protected]): query: SELECT NULL AS password, 'Y' as nopassword, email AS user FROM accounts WHERE email = '[email protected]' AND pass = password('')
Oct 05 15:12:22 auth-worker(7448): Info: sql([email protected]): unknown user
Oct 05 15:12:22 auth: Debug: master out: NOTFOUND 2
Oct 05 15:12:22 lmtp(7467): Debug: auth input:
Oct 05 15:12:22 lmtp(7467): Info: Disconnect from local: Client quit (in reset)
似乎执行了 SQL 查询来查找用户,但没有密码(当然,发送者没有接收者的密码),因此找不到用户。由于我已将 userdb 设置为静态,因此不应执行任何查询,因此不应有任何查询来查找用户。我想我可以通过添加 user_query 来暂时解决这个问题。
PS:我的密码查询来自此(与 MySQL PASSWORD 兼容):http://wiki2.dovecot.org/AuthDatabase/SQL#Password_verification_by_SQL_server
PPS:第二个 SQL 请求用于退回消息,退回失败,表示邮件无法投递。
答案1
我终于找到了解决方案。Postfix 配置为在数据库中查找用户是否存在以发送电子邮件,因此 Dovecot 在从 Postfix 接收电子邮件时不必执行此操作。
这就是它应该如何工作,也是我们定义静态 userdb 的原因。它缺少一个参数,因此 Dovecot 不会检查用户是否存在,因为 Postfix 已经这样做了:
/etc/dovecot/conf.d/auth-sql.conf.ext
(仅有用的部分):
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n allow_all_users=yes
}
添加allow_all_users=yes
参数解决了该问题。