我可以获取最新邮件的主题,但我想循环获取特定日期的所有邮件主题,我也希望获得正文。
这是我的代码
#coding=UTF-8
import imaplib
import ConfigParser
import os
import email
#Gmail
M = imaplib.IMAP4_SSL('imap.gmail.com', 993)
username = 'XXX@gmail.com'
password = 'XXXX'
M.login(username, password)
M.select('Inbox', True)
type,data=M.search(None,'(ON 13-May-2015)')
for num in data[0].split():
type,data = M.fetch(num, '(RFC822)')
text = data[0][1]
message = email.message_from_string(text)
def pSubject(message):
subject = message.get('subject')
h = email.Header.Header(subject)
dh = email.Header.decode_header(h)
subject=dh[0][0]#title
return subject
print pSubject(message) #get subject
M.close()
M.logout()