我在 ubuntu 22.04 上使用 saslauthd 和 postfix 配置客户端身份验证时遇到了一些问题。问题是,尽管用户存在,但用户却没有得到身份验证。这是我第一次设置 postfix 和 saslauthd,所以对于你们这些 serverfault 大牛来说,这可能很明显。
使用 mail 命令发送电子邮件很顺利。使用 telnet 一切正常,但使用带身份验证的远程 SMTP 客户端却不行。我已经花了 6 个小时,几乎要放弃了(就今天而言)。
从远程服务器执行 telnet:
telnet mail.mydomain.com 25
Trying IP...
Connected to mail.mydomain.com.
Escape character is '^]'.
220 mail.mydomain.com ESMTP Postfix (Ubuntu)
EHLO mydomain.com
250-mail.mydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH SCRAM-SHA-1 SCRAM-SHA-256 DIGEST-MD5 NTLM CRAM-MD5 PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
421 4.4.2 mail.mydomain.com Error: timeout exceeded
Connection closed by foreign host.
验证我创建的用户确实存在
testsaslauthd -u lukas -p mypassword -r mydomain.com
0: OK "Success."
/var/log/mail.log(请注意,尽管上面刚刚成功测试,但这里的验证却失败了。
Mar 9 04:36:42 postfix/smtpd[42026]: warning: SASL authentication failure: Password verification failed
Mar 9 04:36:42 postfix/smtpd[42026]: warning: IPbredband.3.dk[IP]: SASL PLAIN authentication failed: authentication failure
Mar 9 04:36:42 postfix/smtpd[42026]: lost connection after AUTH from IP.bredband.3.dk[IP]
Mar 9 04:36:42 postfix/smtpd[42026]: disconnect from IP.bredband.3.dk[IP] ehlo=2 starttls=1 auth=0/1 commands=3/4
我当前正尝试通过 nodemailer 的 SMTP 模块登录(这应该不是问题 - 但安全总比后悔好):
import nodemailer from "nodemailer"
const transporter = nodemailer.createTransport({
host: "mail.mydomain.com",
port: 25,
secure: false, // Use `true` for port 465, `false` for all other ports
auth: {
user: "[email protected]”,
pass: “myapassword
},
});
router.post('/', async (req, res) => {
const info = await transporter.sendMail({
from: '"Maddison Foo Koch
答案1
解决方案是添加修改以下文件 /etc/default/saslauthd
START=yes
DESC="SASL Authentication Daemon"
NAME="saslauthd"
MECHANISMS="sasldb"
MECH_OPTIONS=""
THREADS=5
# modified to look in the chrooted folder which has a symlink to var/run/saslauthd and can be run by postfix
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"