[英]Unable to read e-mails from Outlook for last 1 hour with Python
[英]Unable to Read Outlook Mails by applying filter on sender using python
下面是我使用的代碼
import win32com.client
import os
outlook=win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox=outlook.GetDefaultFolder(6) #Inbox default index value is 6
message=inbox.Items
get_path = os.getcwd()
message2=message.GetLast()
subject=message2.Subject
body=message2.body
date=message2.senton.date()
sender=message2.Sender
attachments=message2.Attachments
for m in message:
if m.sender=='ritwikvijayan@gmail.com':# here in my requirement i will change the dates
print(m.SentOn.strftime("%d-%m-%y %H:%M:%S"))
for x in m.Attachments:
x.SaveASFile(os.path.join(get_path,x.FileName))
print ("successfully downloaded attachments")
我收到此錯誤:AttributeError: .sender
MailItem.Sender
返回一個AddressEntry對象,而不是一個字符串。 您可以使用其名稱和地址屬性。
還要記住Items.GetLast
不會返回您在 Outlook 中看到的最后一個項目。 除非 Items 集合是明確排序的,否則您返回的內容是不確定的。 您很可能會在該文件夾中獲得較舊的創建對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.