【发布时间】:2023-04-15 21:18:01
【问题描述】:
我尝试使用 python 的 pywin32 库制作警报邮件报告仪表板/报告(我是新手), 所以我试图获取详细信息,例如已在默认收件箱文件夹以外的其他文件夹中设置的警报邮件的时间(这也是完全不同文件夹的子文件夹,该父文件夹不属于任何文件夹)默认 Outlook 文件夹)。
import sys, win32com.client, datetime
# Connect with MS Outlook - must be open.
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# connect to Sent Items
s = outlook.GetDefaultFolder(6).Items # "5" refers to the sent item of a
#s.Sort("s", true)
# Get yesterdays date for the purpose of getting emails from this date
d = (datetime.date.today() - datetime.timedelta (days=1)).strftime("%d-%m-%y, %H:%M:%S")
# get the email/s
msg = s.GetLast()
# Loop through emails
while msg:
# Get email date
date = msg.SentOn.strftime("%d-%m-%y , %H:%M:%S")
# Get Subject Line of email
sjl = msg.Subject
# Set the critera for whats wanted
if d == date and (msg.Subject.startswith("XXXX ") or msg.Subject.startswith("XXXXX")):
print(sjl,date)
msg = s.GetPrevious()
所以通过上面的代码,我只能获取默认文件夹中的电子邮件详细信息(例如收件箱/已发送/..)
【问题讨论】:
标签: python python-3.x outlook pywin32 win32com