讀取一封郵件

#python3.1

 

import poplib
import base64
import email
import email.header

 

s=poplib.POP3_SSL('pop3.live.com',995)
s.user('[email protected]')
s.pass_('xxxxxxxxxxxxxx')


#獲取最新一封郵件

n = len(s.list()[1])
ar=s.retr(n)[1]


#獲取消息源數據

msg=''
for m in ar:
    k=m.decode()+'/r/n'
    msg+=k


mail=email.message_from_string(msg)

 

#獲得郵件頭數據
print(mail.get('date'))
sb=mail.get('subject')

 

#解碼
k=email.header.decode_header(sb)[0]
print(k[0].decode(k[1]))
s.quit()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章