Search code examples
pythonpython-3.xoutlookpywin32

Python outlook sent items folder data extraction( using MAPI and pywin32)


Here I am trying to extract one particular email data which is present in sent items folder in outlook? but I am unable to find any method to give such condition , like if this particular email present in sent item folder then extract subject, date & time.

import win32com.client
from win32com.client import Dispatch

import  regex as re
from datetime import datetime, timedelta

outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")

sentitem = mapi.GetDefaultFolder(5)
messages = sentitem.Items


for msg in messages:

here after I am not getting any idea. Can anyone help me to find this


Solution

  • You cannot use regex with the Outlook Object Model, but you can use Items.Find/FindNext and Items.Restrict to find the message(s).

    See https://learn.microsoft.com/en-us/office/vba/api/outlook.items.restrict for the syntax and sample queries.