3

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

ugabuga77
  • 681
  • 2
  • 11
  • 19
  • Can you tell which line is causing the restart? Is the print causing the restart, or getting the CreationTime property? I'm wondering if this is a problem trying to print strings and floats simultaneously. – Peanut Butter Vibes Mar 13 '19 at 17:13

1 Answers1

0

Just tried your code and it worked with no issues. Assuming you have taken some general troubleshooting steps, i.e., restart your computer, etc. I would recommend the following steps:

  1. Close all instances of outlook
  2. Run Outlook in safe mode by pressing Windows Key + R and this dialog appears enter image description here

input outlook /safe just as its shown in the image (above). Attempt to run your script (opening outlook in safe mode ensures no Outlook add-ins/configurations interfere)

If this doesn't work, I would recommend using a debugger (VSCode for example) and running line by line to see where your script is terminating. You shared a sample code, but if you have additional code that you didn't share - only assumptions can be made from my end, but you may have something causing this issue in your script.

Kyle Deer
  • 91
  • 8