无法通过使用python对发件人应用筛选器来读取Outlook邮件



下面是我使用的代码

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对象,而不是字符串。您可以使用其"名称"one_answers"地址"属性。

还要记住,Items.GetLast不会返回您在Outlook中看到的最后一个项目。除非Items集合被明确排序,否则返回的内容是不确定的。您很可能会在该文件夹中获得较旧创建的对象。

最新更新