如何安装并使用 Postfix 发送电子邮件

如何安装并使用 Postfix 发送电子邮件

我正在尝试在服务器上安装 Postfix 并让它通过中继。我希望拥有带有自定义域的电子邮件,因此我购买了一个域名并注册了一个 A 记录以指向中继主机的 IP。注意:我在 Cloudzy 上托管所有服务器 (VPS)。以下是我执行的步骤和我为此所做的配置:

在服务器 A 上,我这样做

apt-get install postfix

apt-get install mailutils

其次是

service postfix restart

在服务器 B 上,我执行完全相同的命令。

在服务器 A 和 B 上,我选择完全相同的选项

Local only
System mail name is bought domain name: *******.com
Root and postmaster recipient are the same: *linuxuser*
Destinations to accept mail are both:  localhost.com, localhost, *******.com
Force synchronous mail: No
Local networks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Mailbox size limit: 0
Local address extension character: +
Internet protocols to use: all

现在,我去编辑服务器 B 上的 /etc/postfix/main.cf 文件并进行以下更改

myhostname = *******.com #bought domain name
mynetworks = <Server A IP address> 127.0.0.0./8
inet_interfaces = all
smtp_enforce_tls = yes
smtp_tls_security_level = encrypt

在服务器 A 上,我也对 main.cf 文件进行了以下更改

relayhost = <Server B IP address>
smtp_enforce_tls = yes
smtp_tls_security_level = encrypt

并排比较两个服务器上的 /etc/postfix/main.cf 文件

服务器 A

...
smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level = encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_enforce_tls = yes

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = *******.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.com, localhost, *******.com
relayhost = <Server B address>
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
default_transport = error
relay_transport = error
inet_protocols = all

服务器 B

...
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level = encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_enforce_tls = yes

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = *******.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost.com, localhost, *******.com
relayhost =
mynetworks = <Server A IP Address> 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
default_transport = error
relay_transport = error
inet_protocols = all

并在两台服务器上重新启动服务。

我将通过以下方式发送测试电子邮件echo "This is the body of the email" \ | mail -s "This is the subject line" <email address I want it sent to>

但是,电子邮件始终发送不出去。请帮忙!我使用的是 Ubuntu 20.04

相关内容