I try to make an alert mail report dashboard/report using python's pywin32 library(I'm new into this), so I'm trying to fetch the details like time of an alert mail that has been set up in some different folder other than the default inbox folder(that is also a subfolder of a different folder altogether, which parent folder is not part of any default outlook folder).
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()
So by the above code I was only able to get the details of email which are in the default folder only (such as inbox/sent/..)