Python 3.5 imaplib电子邮件

Python 3.5 imaplib电子邮件

问题描述:

我在网络上发现了关于imaplib的一些代码,并配置了我的信息我得到了它的工作没有问题与我的Gmail帐户(但我不得不改变一些Gmail配置做到这一点)。Python 3.5 imaplib电子邮件

我试图用我的蔚蓝电子邮件服务相同的代码,但我每次都遇到了同样的错误:

> Traceback (most recent call last): File "C:\Users\Carlo\Desktop\try.py", line 66, in <module> 
>  M = imaplib.IMAP4_SSL('mail.example.com') File "C:\Python34-32\lib\imaplib.py", line 1221, in __init__ 
>  IMAP4.__init__(self, host, port) File "C:\Python34-32\lib\imaplib.py", line 181, in __init__ 
>  self.open(host, port) File "C:\Python34-32\lib\imaplib.py", line 1234, in open 
>  IMAP4.open(self, host, port) File "C:\Python34-32\lib\imaplib.py", line 257, in open 
>  self.sock = self._create_socket() File "C:\Python34-32\lib\imaplib.py", line 1224, in _create_socket 
>  sock = IMAP4._create_socket(self) File "C:\Python34-32\lib\imaplib.py", line 247, in _create_socket 
>  return socket.create_connection((self.host, self.port)) File "C:\Python34-32\lib\socket.py", line 494, in create_connection 
>  for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "C:\Python34-32\lib\socket.py", line 533, in getaddrinfo 
>  for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11004] getaddrinfo failed 

的问题是,我不明白为什么那么我不会不知道,在什么集中解决我的问题...

你能帮我吗?

这是我的代码:

import sys 
import imaplib 
import getpass 
import email 
import email.header 
import datetime 


def process_mailbox(M): 

    rv, data = M.search(None, '(UNSEEN)')#select just un-read documents 
    if rv != 'OK': 
     print("No messages found!") 
     return 


    for num in data[0].split(): 
     rv, data = M.fetch(num, '(RFC822)') 
     if rv != 'OK': 
      print("ERROR getting message", num) 
      return 

     msg = email.message_from_bytes(data[0][1]) 
     print (msg) 
     hdr = email.header.make_header(email.header.decode_header(msg['Subject'])) 
     subject = str(hdr) 
     print('Message %s: %s' % (num, subject)) 
     print('Raw Date:', msg['Date']) 
     # Now convert to local date-time 
     date_tuple = email.utils.parsedate_tz(msg['Date']) 
     if date_tuple: 
      local_date = datetime.datetime.fromtimestamp(
       email.utils.mktime_tz(date_tuple)) 
      print ("Local Date:", \ 
       local_date.strftime("%a, %d %b %Y %H:%M:%S")) 


M = imaplib.IMAP4_SSL('IMAP')#imap of my azure service 

try: 
    rv, data = M.login("email", "password")#my username and password except imaplib.IMAP4.error: 
    print ("LOGIN FAILED!!! ") 
    sys.exit(1) 

rv, data = M.select("Inbox") #select data from inbox folder if rv == 'OK': 
    print("Processing mailbox...\n") 
    process_mailbox(M) 
    M.close() else: 
    print("ERROR: Unable to open mailbox ", rv) 

M.logout() 

新信息:

家伙,我没有收到这么多的帮助,到目前为止,所以我准备好文件,并通过自己的努力,我尝试用IP该机器的地址和IMAP指定的端口,我这次得到了不同的错误..... 这是我编辑的代码:

M = imaplib.IMAP4_SSL('IMAP or IP Address','143') 

try: 
    rv, data = M.login(EMAIL_ACCOUNT, passwd) 
except imaplib.IMAP4.error: 
    print ("LOGIN FAILED!!! ") 
    sys.exit(1) 

这一次的错误是这个:

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

一些帮助,请!?!?!?

+0

SSL服务器侦听端口993,而不是143. – Max

这是一个DNS错误。它找不到您尝试连接的主机的名称。

+0

嗨@Max我没有放置主机,因为我不想真的分享地址;我尝试使用机器的IP地址和IMAP地址,这次我指定端口号,然后收到另一个错误...我要编辑我的问题;)请让我知道你是否可以帮助我。 ..谢谢 –