Benformance
Benformance

Reputation: 21

Read contents of a selected Outlook e-mail using python

I have this simple piece of code that reads the content of the last e-mail in my inbox.

How can I do the same for e-mail I click on/highlight within Outlook?

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6) 
messages = inbox.Items
message = messages.GetLast()
print(message.body) 

Upvotes: 2

Views: 788

Answers (1)

0m3r
0m3r

Reputation: 12497

Simply use ActiveExplorer().Selection(1)

Example

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application")
messages = outlook.ActiveExplorer().Selection
message = messages(1)
print(message.body)

Upvotes: 1

Related Questions