I'm currently trying calculate the leadtime of all outlook messages within a specific outlook folder using python. In general the script runs fine however, after roundabout 2000 emails I received the following error (part of code):
import win32com.client as win32
import pandas as pd
from datetime import date
import time
outlook = win32.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders("example@example.com")
inbox = folder.Folders("Inbox")
messages = inbox.Items
df = pd.DataFrame()
index = 0
for msg in messages:
if (msg.SenderEmailType != "EX"):
print(str(msg.subject))
print('Begin date:', msg.SentOn.strftime('%Y-%m-%d'))
print('End date:',msg.LastModificationTime.strftime('%Y-%m-%d'))
df.at[index, 'Subject'] = msg.subject
df.at[index, 'Begin date'] = msg.SentOn.strftime('%Y-%m-%d')
df.at[index, 'End date'] = msg.LastModificationTime.strftime('%Y-%m-%d')
I encounterd the following error:
Traceback (most recent call last):
File "C:\Users\USER\Desktop\MailCounts.py", line 24, in <module>
print('End date:',msg.LastModificationTime.strftime('%Y-%m-%d'))
File "C:\Users\USER\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
ValueError: microsecond must be in 0..999999
I tried to debug it by selecting the specific email and put it into another outlook folder and then loop over it. But then it works fine without errors. So it seems to be folder specific?!
I have searched for several answers on the errors and the method in general. But as far as I can see, this answer was never asked before with a suitable answer. Thanks in advance!