I'm trying to read outlook emails via python, have code like below:
import win32com.client
import os
from datetime import datetime, timedelta
outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace('MAPI')
messages = mapi.Folders("[email protected]").Folders("Inbox").Folders("Test").Items
today_change = timedelta(7)
today = datetime.today()
start_date = today - today_change
start_date = start_date.strftime('%Y-%m-%d %H:%M %p')
today = today.strftime('%Y-%m-%d %H:%M %p')
messages = messages.Restrict("[ReceivedTime] >= '" start_date
"' And [ReceivedTime] <= '" today "' And @SQL=(urn:schemas:httpmail:subject LIKE '