Postfix自建SMTP服务


安装Postfix和mailutils

sudo apt install postfix mailutils

使用25端口发件

简单测试一下

访问https://www.mail-tester.com/网址,会获得一个测试邮箱发件质量的临时邮箱地址,使用自建的SMTP邮箱向这个地址发件。

echo "mail content" | mail -s "mail title" [email protected]

发件后点击”查看你的邮件得分“:

0.7分,非常大的概率会被认做垃圾邮件。

使用587端口发件

安装SASL(Simple Authentication and Security Layer)库

sudo apt-get install postfix libsasl2-modules

配置SASL

编辑/etc/postfix/main.cf

添加以下行:

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_mechanism_filter = plain

创建SASL密码文件

创建/etc/postfix/sasl_passwd

该文件包含 SMTP 服务器的认证凭据。每行格式如下:

[smtp.example.com]:587 username:password

保存文件后,运行以下命令以生成密码数据库:

sudo postmap /etc/postfix/sasl_passwd

配置发送邮件的主机名

在/etc/postfix/main.cf中找到myhostname,设置为:

myhostname = yourhostname.example.com

启用 TLS/SSL 加密

在 /etc/postfix/main.cf 中添加以下行:

smtp_tls_security_level = encrypt
smtpd_tls_security_level = may

重启 Postfix

sudo systemctl restart postfix

再次简单测试一下

echo "mail content" | mail -s "mail title" [email protected]

查看测试结果:https://www.mail-tester.com/test-2wyit102d

,

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注