531 字
3 分钟
PVE设置自带的邮件推送
PVE设置自带的邮件推送
既然测试邮件能收到但备份邮件不行,而你又提到了 Postfix,这通常是因为备份任务发送邮件时的“发件人地址”不符合邮件服务器的校验规则(许多运营商如 QQ/Gmail 要求发件人必须与登录账号一致)。
以下是在 PVE 中配置 Postfix 外部中继(SMTP Relay)的标准流程:
1. 安装必要组件
确保系统有 SASL 认证支持:
apt update && apt install libsasl2-modules -y2. 配置 Postfix 账号密码
你需要创建一个保存邮箱账号和授权码(或密码)的文件。
- 创建/编辑密码文件:
nano /etc/postfix/sasl_passwd- 写入以下内容(替换为你的信息):
[smtp.example.com]:587 your-email@example.com:your-password-or-token(注:保留中括号,smtp.example.com 换成你的服务器,如 smtp.qq.com 或 smtp.gmail.com)
- 设置权限并生成数据库:
chmod 600 /etc/postfix/sasl_passwdpostmap /etc/postfix/sasl_passwd3. 修改 Postfix 主配置文件
编辑 /etc/postfix/main.cf,在文件末尾添加或修改以下配置:
# 转发服务器地址relayhost = [smtp.example.com]:587
# 启用 SASL 认证smtp_sasl_auth_enable = yessmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwdsmtp_sasl_security_options = noanonymous
# 启用 TLS 加密smtp_use_tls = yessmtp_tls_security_level = encryptsmtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt4. 解决“发件人拒绝”的关键:地址重写 (关键步骤)
备份任务发送时,PVE 默认可能使用 root@your-hostname。如果你的邮件商要求 From 必须是 your-email@example.com,备份邮件就会被拒绝。
- 编辑
/etc/postfix/generic:
nano /etc/postfix/generic- 添加以下映射,将所有系统生成的邮件地址都重写为你的真实发件邮箱:
root@pam your-email@example.comroot@localhost your-email@example.comroot@pve your-email@example.com- 生成数据库并重启服务:
postmap /etc/postfix/generic# 在 main.cf 中启用此映射echo "smtp_generic_maps = hash:/etc/postfix/generic" >> /etc/postfix/main.cfsystemctl restart postfix5. 如何验证是否修复?
使用 journalctl 实时监控,然后去手动跑一个备份:
journalctl -u postfix -f重点观察日志:
- 如果看到
status=sent (250 OK):说明发送成功,去垃圾箱找找。 - 如果看到
Sender address rejected: not owned by user:说明你的 Step 4 (地址重写) 没生效或填错了。 - 如果看到
Authentication failed:请检查 Step 2 的账号和授权码。