- 论坛徽章:
- 0
|
顺利解决了,呵呵:)
顺便把我修改的代码贴过了
stmplib.py 中的代码
AUTH_PLAIN = "PLAIN"
AUTH_CRAM_MD5 = "CRAM-MD5"
AUTH_LOGIN = "LOGIN"
if self.helo_resp is None and self.ehlo_resp is None:
if not (200 <= self.ehlo()[0] <= 299):
(code, resp) = self.helo()
if not (200 <= code <= 299):
raise SMTPHeloError(code, resp)
if not self.has_extn("auth"):
raise SMTPException("SMTP AUTH extension not supported by server.")
# 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]
preferred_auths = [AUTH_CRAM_MD5, AUTH_PLAIN, AUTH_LOGIN]# add LOGIN
#preferred_auths = [AUTH_PLAIN, AUTH_CRAM_MD5]
# Determine the authentication method we'll use
authmethod = None
for method in preferred_auths:
if method in authlist:
authmethod = method
break
if '='+method in authlist:
authmethod = method
break # 本来这个部分不用加,但是我那个邮件服务器返回的是 auth=LOGIN,多了一个'=',所以我就加了这一段
if self.debuglevel > 0:
print "AuthMethod:", authmethod
if authmethod == AUTH_CRAM_MD5:
(code, resp) = self.docmd("AUTH", AUTH_CRAM_MD5)
if code == 503:
# 503 == 'Error: already authenticated'
return (code, resp)
(code, resp) = self.docmd(encode_cram_md5(resp, user, password))
elif authmethod == AUTH_PLAIN:
(code, resp) = self.docmd("AUTH",
AUTH_PLAIN + " " + encode_plain(user, password))
# 主要就是下面这一段了
elif authmethod == AUTH_LOGIN:
(code, resp) = self.docmd("AUTH", AUTH_LOGIN)
if code == 334:
(code, resp) = self.docmd(base64.encodestring(user)[:-1])
if code == 334:
(code, resp) = self.docmd(base64.encodestring(password)[:-1])
elif authmethod == None:
raise SMTPException("No suitable authentication method found.")
if code not in [235, 503]:
# 235 == 'Authentication successful'
# 503 == 'Error: already authenticated'
raise SMTPAuthenticationError(code, resp)
return (code, resp)
[ 本帖最后由 白色乌鸦 于 2006-9-30 18:00 编辑 ] |
|