我可以连接到我们的IMAP服务器,但无法进行身份验证。我尝试使用IMAP.login方法,但是随后我得到了不正确的用户名和密码(我知道100%确保用户名和密码正确)。
所以我想用IMAP.authenticate尝试一下。根据功能:
(b'AUTH=DIGEST-MD5', b'ENABLE', b'IDLE', b'IMAP4REV1', b'LITERAL+', b'LOGINDISABLED', b'METADATA-SERVER', b'QUOTA', b'SASL-IR', b'UIDPLUS')
我知道我必须使用DIGEST-MD5作为机制。但是我不知道该如何使用authobject。
所以我到目前为止是:
import imaplib
import hashlib
hash = hashlib.md5('username'.encode('UTF-8'))
usn = hash.digest()
with imaplib.IMAP4_SSL(host="hostx.com", port=221) as sess:
print(sess.capability())
# z = sess.login('username', 'password')
# print(z)
resp = sess.authenticate('DIGEST-MD5', usn)
但这显然不起作用。我得到的错误:
Traceback (most recent call last):
File "C:/Users/starr499/Documents/imap_vvm_poc/vvm_poc.py", line 31, in <module>
resp = sess.authenticate('DIGEST-MD5', usn)
File "C:\Users\starr499\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 428, in authenticate
typ, dat = self._simple_command('AUTHENTICATE', mech)
File "C:\Users\starr499\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 1196, in _simple_command
return self._command_complete(name, self._command(name, *args))
File "C:\Users\starr499\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 996, in _command
literal = literator(self.continuation_response)
File "C:\Users\starr499\AppData\Local\Programs\Python\Python37-32\lib\imaplib.py", line 1373, in process
ret = self.mech(self.decode(data))
TypeError: 'bytes' object is not callable
我应该如何使用IMAP.authenticate?