Reputation: 735
I'm successfully connecting to and reading through my Outlook inbox using some code modified from: Reading e-mails from Outlook with Python through MAPI. What I'd like to do is search my inbox for certain email subjects. I can do this by just looping through all emails but wondering if there is a more elegant (perhaps using MAPI) way to search the inbox? I've looked through the MailItem methods but can't seem to find anything.
Thanks
Upvotes: 1
Views: 5835
Reputation: 49405
You need to use the AdvancedSearch method of the Application class which allows to search for items in multiple folders. The Restrict and Find/FindNext methods of the Items class allow to search for items in the single folder only.
The key benefits of using the AdvancedSearch method in Outlook are:
AdvancedSearch
method runs it automatically in the background.Restrict
and Find
/FindNext
methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).Stop
method of the Search class.Read more about the AdvancedSearch
method in the Advanced search in Outlook programmatically: C#, VB.NET article. Note, the Outlook object model is common for all programming languages, so it doesn't matter whether Python or C# is used.
Upvotes: 1
Reputation: 66255
The link you posted talks about using Outlook Object Model, not MAPI - Extended MAPI is a completely different API accessible from C++ or Delphi, but not from Python.
To search for an email, use Items.Find/FindNext
or Items.Restrict
(where Items collection comes from the MAPIFolder.Items
property) - see https://msdn.microsoft.com/en-us/library/ms268869.aspx for an example.
Upvotes: 0