使用 Python 或 Telnet 通过 postfix 发送电子邮件

使用 Python 或 Telnet 通过 postfix 发送电子邮件

我设法配置了一个本地 postfix 服务器,它在使用mail命令时可以正常工作(并且我从 cron 守护进程接收电子邮件),

telnet localhost 25但是,如果我尝试使用服务器进行连接,将不会响应命令,并且 CTRL+D 将不会退出(它会冻结)或使用 python:

import smtplib
server = smtplib.SMTP('localhost', 25)
server.connect()

连接也会冻结

有人知道这可能来自哪里吗?

供参考,postfix 通过 GMail 发送我的邮件,这是我的配置:

mydomain_fallback = localhost
message_size_limit = 10485760
biff = no
mynetworks = 127.0.0.0/8, [::1]/128
smtpd_client_restrictions = permit_mynetworks permit_sasl_authenticated permit
recipient_delimiter = +
smtpd_tls_ciphers = medium
inet_protocols = all
inet_interfaces = loopback-only

# Gmail
relayhost=[smtp.gmail.com]:587
smtp_sasl_auth_enabled=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=noanonymous
smtp_sasl_auth_enable=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom

mail.log下面是使用 python 连接时的尾部:

May 13 16:06:33 potiron postfix/master[12808]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling
May 13 16:06:33 potiron postfix/postscreen[21559]: CONNECT from [127.0.0.1]:59676
May 13 16:06:33 potiron postfix/postscreen[21559]: WHITELISTED [127.0.0.1]:59676
May 13 16:07:33 potiron postfix/smtpd[21562]: warning: database /etc/aliases.db is older than source file /etc/aliases
May 13 16:07:33 potiron postfix/smtpd[21562]: fatal: open /etc/postfix/submit.cred: No such file or directory
May 13 16:07:34 potiron postfix/master[12808]: warning: process /usr/libexec/postfix/smtpd pid 21562 exit status 1
May 13 16:07:34 potiron postfix/master[12808]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling

看来我的连接已列入白名单,但是,它似乎从 59676 连接,这与 有冲突吗mynetworks = 127.0.0.0/8, [::1]/128

答案1

在该日志转储的倒数第三行中,它显示“致命:打开 /etc/postfix/submit.cred:没有这样的文件或目录”。在您的配置文件中的某个地方,您引用了 /etc/postfix/submit.cred 。它看起来不像在您的主 postfix 配置中,但它可能在辅助配置之一中,或者它也可能在您的 sasl 身份验证配置的某个地方(我相信。我不确定 SASL 是否被白名单完全绕过)。

顺便提一下,您的 /etc/aliases.db 已过期。您编辑了 /etc/aliases,但没有刷新 aliases.db。

相关内容