使用imaplib2阅读用户电子邮件内容

时间:2019-05-10 09:52:06

标签: python-2.7

我正在编写一个python代码,以使用imaplib2软件包从邮件服务器(无论是Google还是Outlook)中读取电子邮件。我的代码出现以下错误。谁能告诉我该如何解决。我是否只需要使用port = 993和host = imap,如果可以的话,如何连接到我需要的服务器

import imaplib2
import base64
email_user = 'mailid'
email_pass = 'password'
email_server = 'ns21.interactivedns.com'

Mail = imaplib2.IMAP4_SSL(email_server, 995) # used this server and port since I'm trying to read mail contents from this server
Mail.login(email_user, email_pass)
Mail.select('Inbox')

type, messages = Mail.search(None, 'ALL')

我正在整理错误:

Traceback (most recent call last):
  File "C:/Users/user01/PycharmProjects/MongoAlchemy/client.py", line 6, in <module>
    M = imaplib2.IMAP4_SSL('ns21.interactivedns.com', 995)
  File "C:\Users\user01\PycharmProjects\MongoAlchemy\venv\lib\site-packages\imaplib2\imaplib2.py", line 2073, in __init__
    IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout, debug_buf_lvl)
  File "C:\Users\user01\PycharmProjects\MongoAlchemy\venv\lib\site-packages\imaplib2\imaplib2.py", line 392, in __init__
    raise self.error('unrecognised server welcome message: %s' % repr(self.welcome))
imaplib2.imaplib2.error: unrecognised server welcome message: None

0 个答案:

没有答案