Is there a way to search for the last email that I sent to an address in outlook in python?

Viewed 24

I am trying to figure out if there is a way to search for the last email that I sent to an address in my Outlook sent folder, and to reply all to that. It’s probably just me, but the win32 module‘s documentation is very hard to follow.

1 Answers

There is no need to iterate over all items in the folder in that case. Instead, you can use the Find/FindNext or Restrict methods of the Items class from the Outlook object model to get items that were sent to a specific recipient (email address). Read more about these methods in the following articles that I wrote for the technical blog:

For example, you could use the following search criteria to find items that were sent to the sample email address (VBA syntax):

criteria = "@SQL=" & Chr(34) & "urn:schemas:httpmail:to" & Chr(34) & " like '%sample@email.com%'" 

See Filtering Items Using a String Comparison for more information.

Then you can sort the found items and get the latest one from the Items collection.

As soon as you find the required item you may call the ReplyAll method.

Related