虽然我在从很多网站上搜索了很多之后做了大部分工作,但我仍然无法获得我想要的正确输出。
代码:
import imaplib
import smtplib
import email
mail=imaplib.IMAP4_SSL("imap.gmail.com")
mail.login("**************@gmail.com","********")
mail.select('inbox')
type,data=mail.search(None,'ALL')
mail_ids=data[0]
id_list=mail_ids.split()
for i in range(int(id_list[-1]),int(id_list[0])-1,-1):
typ,data=mail.fetch(i,'(RFC822)')
for response_part in data :
if isinstance(response_part,tuple):
msg=email.message_from_string(response_part[1])
email_from=msg['from']
email_subj=msg['subject']
c=msg.get_payload(0)
print email_from
print "subj:",email_subj
print c
输出:
Bharath Joshi subj: hehe From nobody Tue Dec 25 15:48:52 2018 Content-Type: text/plain; 字符集=“UTF-8”
你好444444444
Bharath Joshi subj: From nobody Tue Dec 25 15:48:52 2018 Content-Type: text/plain; 字符集=“UTF-8”
33333
Bharath Joshi subj: From nobody Tue Dec 25 15:48:53 2018 Content-Type: text/plain; 字符集=“UTF-8”
你好--22
困扰我的是我得到的额外东西
“来自任何人......”和“内容类型......”
我怎样才能删除那些?
拉莫斯之舞
相关分类