【python】smtplib修改

描述:

1、qmail搭建了一套邮件系统,python通过smtp发送邮件,遇到发送失败。

2、排查发现smtplib.py 中authmethod 优先匹配了AUTH_CRAM_MD5

源代码:

# Authentication methods the server supports:
authlist = self.esmtp_features[“auth”].split()

# List of authentication methods we support: from preferred to
# less preferred methods. Except for the purpose of testing the weaker
# ones, we prefer stronger methods like CRAM-MD5:
preferred_auths = [AUTH_CRAM_MD5, AUTH_PLAIN,AUTH_LOGIN,]

# Determine the authentication method we’ll use
authmethod = None
for method in preferred_auths:
if method in authlist:
authmethod = method
break

 

修改之后:

        # Authentication methods the server supports:
        authlist = self.esmtp_features["auth"].split()

        # List of authentication methods we support: from preferred to
        # less preferred methods. Except for the purpose of testing the weaker
        # ones, we prefer stronger methods like CRAM-MD5:
        preferred_auths = [AUTH_LOGIN, AUTH_CRAM_MD5, AUTH_PLAIN]

        # Determine the authentication method we'll use
        authmethod = None
        for method in preferred_auths:
            if method in authlist:
                authmethod = method
                break

 

修改之后邮件正常发送。

此条目发表在技术生涯分类目录,贴了, 标签。将固定链接加入收藏夹。