0
我「從」空白即無法獲得發件人地址獲取使用IMAP4
c.select('INBOX', readonly=True)
for i in range(1, 30):
typ, msg_data = c.fetch(str(i), '(RFC822)')
for response_part in msg_data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
for header in [ 'subject', 'to', 'from' ]:
print '%-8s: %s' % (header.upper(), msg[header])
及彼頭空白髮件人的電子郵件ID是輸出
主題:下面是測試題目
TO : 「[email protected]」
FROM:
編輯1
即使我沒有得到消息ID即消息ID也是空白。 我甚至嘗試這種代碼也
typ, data = mb.fetch(num_id, '(BODY[HEADER.FIELDS (MESSAGE-ID)])')
msg_str = email.message_from_string(data[0][1])
message_id = msg_str.get('Message-ID')
print message_id
郵件是否實際上有一個From頭?它可能會丟失! – Max
是的消息實際上有一個空白的From頭。 office365 致:「[email protected]」<[email protected]> 密送:有人隱藏<[email protected]> 來自: 主題:這裏是測試主題 日期:Wed ,2017年5月24日16時06分50秒-0400 –
所以,如果從標題是空白的,爲什麼你會期望的輸出不爲空? – Max