我试图得到最后1000封邮件,我收到的Outlook。但该代码只从主文件夹获取电子邮件,而不是从子文件夹.请协助。
import win32com.client
import pandas as pd
import dateutil.parser
from datetime import datetime
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
# the inbox. You can change that number to reference
# any other folder
messages = inbox.Items
messages.Sort("[ReceivedTime]", True)
i=1
df = pd.DataFrame(columns=['Sender','Subject','DateTime'])
Today = datetime.now().strftime("%m/%d/%Y") # current date and time
while i<1000:
message=messages[i]
DT1=message.ReceivedTime
DT = DT1.strftime("%m/%d/%Y, %H:%M:%S")
a=message.SenderEmailAddress
if "-" in a:
a=a.split("-",1)[1]
b=message.subject
df = df.append({'Sender':a,'Subject':b,'DateTime':DT}, ignore_index=True)
i+=1
df.to_excel("C:/Users/abc/Downloads/Email.xlsx")
要在多个文件夹中进行搜索,你需要使用 "搜索 "功能。AdvancedSearch
的方法 Application
类。的主要好处。AdvancedSearch
方法在Outlook中是。
AdvancedSearch
方法在后台自动运行。Restrict
和 Find
FindNext
方法可以应用到特定的 Items
集合。IsInstantSearchEnabled
的财产 Store
类)。)阅读更多关于 AdvancedSearch
的方法,并找到样品在 在Outlook中以程序方式进行高级搜索。C#, VB.NET 文章:
该。Restrict
或 Find
FindNext
的方法 Items
类只允许根据你的条件从一个文件夹中获取物品。