[英]python script to download attachments in email having keywords in subject line
import getpass, poplib, email, parse
from poplib import POP3
user = 'rnandipati@qwerty.com'
M = poplib.POP3_SSL('outlook.office365.com', '995')
M.user(user)
M.pass_('R7!')
numMessages = len(M.list()[1])
print ("You have %d messages." % (numMessages))
print ("Message List:")
M.quit()
我有上面的代碼,它給出了我的電子郵件中的郵件數量。 我想從主題行中包含“hello”的郵件中下載附件。
我嘗試過的:
for mList in range(numMessages):
for msg in M.retr(mList+1)[1]:
if msg.startswith('Subject'):
print(msg)
break
我在網上看了很多例子,真的需要幫助。 我也是這種腳本的新手。
謝謝。
引用文檔:
POP3.retr( 其中 )
檢索整個消息號,其 ,並設置其可見標志。 結果是形式(響應,['line',...],八位字節)。
所以M.retr(mList+1)[1]
是一個行列表。
您正在迭代一個字符串列表,它可以是unicode ou字節字符串。
文檔沒有說明你得到的字符串類型,但是,如果你使用的是Python 3,我會假設它是unicode字符串。
所以: msg.startswith("Subject:")
應該有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.