=============================pop3=================================
- import poplib
- emailServer = poplib.POP3('192.168.88.7')
- emailServer.user('qa01@corp.globalmarket.com')
- emailServer.pass_('123456')
- # 获取一些统计信息
- emailMsgNum, emailSize = emailServer.stat()
- print 'email number is %d and size is %d'%(emailMsgNum, emailSize)
- # 遍历邮件,并打印出每封邮件的标题
- for i in range(emailMsgNum):
- for piece in emailServer.retr(i+1)[1]:
- if piece.startswith('Subject'):
- print '\t' + piece
- break
- emailServer.quit()
=============================imap=================================
- import imaplib, string, email
- M = imaplib.IMAP4_SSL("imap.gmail.com")
- print M
- try:
- try:
- M.login('chemboking@gmail.com','kawayime')
- 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()