2016-11-21 75 views
0

我在網絡上發現了關於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

回答

1

這是一個DNS錯誤。它找不到您嘗試連接的主機的名稱。

+0

嗨@Max我沒有放置主機,因爲我不想真的分享地址;我嘗試使用機器的IP地址和IMAP地址,這次我指定端口號,然後收到另一個錯誤...我要編輯我的問題;)請讓我知道你是否可以幫助我。 ..謝謝 –

相關問題