Reputation: 21
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
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