现在的位置: 首页 > 综合 > 正文

python取得IMAP服务器邮件

2014年02月28日 ⁄ 综合 ⁄ 共 523字 ⁄ 字号 评论关闭
import imaplib, string, email  
M = imaplib.IMAP4_SSL("imap.163.com")  
print M  
try:  
    try:  
        M.login('xxx@xxx.com','xxxxxx')  
    except Exception,e:  
        print 'login error: %s' % e  
        M.close()  
    M.select()  
    result, message = M.select()  
    typ, data = M.search(None, 'ALL')  
    for num in string.split(data[0]):  
        try:  
            typ, data = M.fetch(num, '(RFC822)')  
            msg = email.message_from_string(data[0][1])  
            print msg["From"]  
            print msg["Subject"]  
            print msg["Date"]  
            print "_______________________________"  
        except Exception,e:  
            print 'got msg error: %s' % e              
    M.logout()  
    M.close()  
except Exception, e:  
    print 'imap error: %s' % e  
    M.close()  

【上篇】
【下篇】

抱歉!评论已关闭.