我尝试使用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()
因此,通过上面的代码,我只能获得默认文件夹中的电子邮件详细信息(如inbox/sent/)
可以使用Stores属性,该属性返回一个Stores集合对象,该对象表示当前配置文件中的所有Store对象。
Store
类提供了GetDefaultFolder方法,该方法返回一个Folder
对象,该对象表示存储中的默认文件夹,并且是由FolderType
参数指定的类型。此方法类似于NameSpace
对象的GetDefaultFolder
方法。不同之处在于,此方法获取与帐户关联的传递存储上的默认文件夹,而NameSpace.GetDefaultFolder
返回当前配置文件的默认存储上的默认文件夹。或者,您可以在存储区中的所有文件夹上进行迭代,如以下VBA宏示例代码所示:相关问题 更多 >
编程相关推荐