如何在postfix中从出站端口25切换到587

lap*_*asz 0 email smtp postfix

我想发送邮件到 Gmail 地址:

echo "This is the body of the email" | mail -s "This is the subject line" user@gmail.com
Run Code Online (Sandbox Code Playgroud)

这就是我在日志中看到的

connect to gmail-smtp-in.l.google.com[142.250.27.27]:25: Connection refused
connect to gmail-smtp-in.l.google.com[2a00:1450:4025:401::1a]:25: Network is unreachable
connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4025:c03::1a]:25: Network is unreachable
connect to alt1.gmail-smtp-in.l.google.com[142.251.9.27]:25: Connection refused
connect to alt2.gmail-smtp-in.l.google.com[142.250.150.27]:25: Connection refused
Apr  9 20:04:02 ubuntu postfix/smtp[157056]: 228717CAA0: to=<user@gmail.com>, relay=none, delay=0.22, delays=0.09/0.09/0.04/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.google.com[142.250.150.27]:25: Connection refused)
Run Code Online (Sandbox Code Playgroud)

尝试使用 netcat 测试此目的地,结果是相同的:

ubuntu@ubuntu:~$ nc -zvn 142.251.9.27 25
nc: connect to 142.251.9.27 port 25 (tcp) failed: Connection refused
Run Code Online (Sandbox Code Playgroud)

然后我使用以下命令检查了端口 587 - 一切正常:

ubuntu@ubuntu:~$ openssl s_client -connect smtp.gmail.com:587 -starttls smtp
CONNECTED(00000003)
depth=2 C = US, O = Google Trust Services LLC, CN = GTS Root R1
verify return:1
depth=1 C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
verify return:1
depth=0 CN = smtp.gmail.com
verify return:1
Run Code Online (Sandbox Code Playgroud)

所以我尝试强制 postfix 根据使用加密,因此修改了 main.cf:

smtpd_tls_security_level=encrypt
smtp_tls_security_level=encrypt
Run Code Online (Sandbox Code Playgroud)

但仍尝试使用被阻止的端口 25。所以我的问题是,如何强制 postfix 使用 25 以外的端口才能发送外发邮件?

vid*_*rlo 5

但仍尝试使用被阻止的端口 25。所以我的问题是,如何强制 postfix 使用 25 以外的端口才能发送外发邮件?

不能

或者,您可以强制 Postfix 这样做。但世界其他地方希望电子邮件通过端口 25 发送。使用端口 587 不起作用 - 这用于经过身份验证的提交(提示:该端口是这样命名的)。不适用于 SMTP 服务器到 SMTP 服务器的通信。

必须告诉您的 ISP 打开端口 25。任何商业 ISP 都应该满足这样的请求。