-2

Am new to Python and wanted to try to automate a manual process.

Iterate through outlook folders and search by key word "Approved" or "Approve" or "approved" or "approve" in the email body. When found, convert to pdf and then save the pdf in a shared drive or SharePoint folder which is uniquely named.

If email has attachments, then save the attachments as well. Is this possible to program in Python?

We have Outlook 2013 but I learned that Outlook 365 has some features. VBA in outlook is grayed out. Any help is much appreciated!

Best Regards, APA

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Vbanovice
  • 1
  • 2
  • 1
    What have you tried so far? – Dmitry Streblechenko Jan 24 '22 at 01:31
  • I am still exploring tools to use to serve my specific needs. After some research, found out Alteryx is ruled out. That leaves Python, which is new to me and then Exceptor which requires little to no coding from what I hear. Thanks for your response, much appreciated! – Vbanovice Jan 26 '22 at 01:18
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 01 '22 at 19:52

1 Answers1

0

Yes, it is possible. You can automate Outlook from python. See Automating Outlook using Python win32com to get started quickly.

Iterate through outlook folders and search by key word "Approved" or "Approve" or "approved" or "approve" in the email body.

There is no need to iterate through Outlook folders. Instead, you may consider using the AdvancedSearch method of the Application class.

The key benefits of using the AdvancedSearch method in Outlook are:

  • The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
  • Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
  • Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
  • You can stop the search process at any moment using the Stop method of the Search class.

Read more about the AdvancedSearch method in the Advanced search in Outlook programmatically: C#, VB.NET article.

You can use the Word editor to save the item using the PDF file format:

Word.Document doc = mailItem.GetInspector.WordEditor;
doc.SaveAs2(fullPath, FileFormat: Word.WdSaveFormat.wdFormatPDF);

Also you may consider using the ExportAsFixedFormat method from the Word object model which saves a document as PDF or XPS format.

The Attachment.SaveAsFile method saves the attachment to the specified path.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • This code serves my purpose but am new to Python, so would need to learn in order to understand the code syntax and the flow. Thanks a bunch for sharing, much appreciated! – Vbanovice Jan 26 '22 at 01:19