1. 安装

1
sudo apt install mailutils -y

2. Postfix 配置向导

按向导逐步选择/填写:

  1. 选择配置类型:第三个选项
    Postfix 配置界面

  2. 使用默认值
    Postfix 配置界面

  3. 填写中继主机(relayhost):[smtp.qq.com]:587
    Postfix 配置界面

  4. 指定 root 邮件接收人(本地用户名或外部邮箱),此处示例为本地用户名
    Postfix 配置界面

  5. 指定应投递到本地的域名。仅发不收,留空即可
    Postfix 配置界面

  6. 系统策略:默认即可
    Postfix 配置界面

  7. 允许作为中继的网段:仅本地环回(默认)
    Postfix 配置界面

  8. 本地邮箱文件大小限制:使用默认的无限制
    Postfix 配置界面

  9. 本地地址扩展分隔符:留空或默认
    Postfix 配置界面

  10. 网络协议监听:默认 all 即可

3. 在 main.cf 中开启 TLS 与 SASL

编辑配置并追加以下内容:

1
2
3
4
5
6
7
8
# 以下为 TLS 与 SASL 认证配置(relayhost 已在向导中设置为 [smtp.qq.com]:587)
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# 可选:增加调试信息
# debug_peer_level = 2
1
sudo vim /etc/postfix/main.cf

4. 配置 QQ 邮箱授权信息

编辑密码文件并生成映射、设置权限:

1
sudo vim /etc/postfix/sasl_passwd

文件内容示例(请替换为你的邮箱与授权码):

1
[smtp.qq.com]:587 [email protected]:你的授权码

生成映射并限权:

1
2
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd*

5. 配置发件地址映射(generic)

先查看当前主机名:

1
2
grep "^myhostname" /etc/postfix/main.cf
# 内容示例:myhostname = iehtian-VMware-Virtual-Platform

编辑 generic 映射:

1
sudo vim /etc/postfix/generic

内容示例(将本机账户映射为你的 QQ 邮箱):

1
2
iehtian@iehtian-VMware-Virtual-Platform [email protected]
@iehtian-VMware-Virtual-Platform [email protected]

6. 重启服务

1
sudo systemctl restart postfix

7. 发送测试邮件

1
echo "测试邮件 $(date)" | mail -s "测试邮件" [email protected]