I'm trying to get date related info from messages that Python retrieves from Outlook but for some weird reason I cannot.
It is strange because I can obtain all info about sender, email body, subject, cc, bc, attachment etc. but when it comes to properties like SentOn, CreationTime or LastModificationTime IDLE just restarts (without any warnings, errors and exceptions).
Here is sample code:
import win32com.client
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
message = messages.GetLast()
rec_time = message.CreationTime
body_content = message.body
subj_line = message.subject
print(rec_time, body_content, subj_line)
Output:
>>>
================= RESTART: C:/Users/XXXXX/Desktop/email.py =================
=============================== RESTART: Shell ===============================
>>>
And here outpoot when CreationTime is commented out:
Hi,
I really think that it is weird that win32 cannot read date info
Your sincerely,
Myself
Andrew
Python ver 3.7, Outlook 2016