Vincent
Vincent

Reputation: 21

Outlook / Python : Open specific message at screen

I want to do a "simple" task in Outlook, with a Python script, but I'm usually in PHP and it's a little bit difficult for me.

Here is the task:

I want to open the "real" message windows at screen, not just to access to the content. Is it possible?

Upvotes: 1

Views: 1728

Answers (2)

Somdeb Mukherjee
Somdeb Mukherjee

Reputation: 178

Here is another example with exchangelib in python:

https://medium.com/@theamazingexposure/accessing-shared-mailbox-using-exchangelib-python-f020e71a96ab

Here is the snippet to get the last email. I did it using a combination of order by and picking the first one or the last one depending on how you order by:

from exchangelib import Credentials, Account, FileAttachment

credentials = Credentials('FirstName.LastName@Some_Domain.com', 'Your_Password_Here')
account = Account('FirstName.LastName@Some_Domain.com', credentials=credentials, autodiscover=True)
filtered_items = account.inbox.filter(subject__contains='Your Search String Here')
print("Getting latest email for given search string...")
for item in account.inbox.filter(subject__contains='Your Search String Here').order_by('-datetime_received')[:1]:   #here is the order by clause:: you may use order_by('datetime_received')[:-1]
    print(item.subject, item.text_body.encode('UTF-8'), item.sender, item.datetime_received) #item.text_body.encode('UTF-8') gives you the content of email

while trying to open the real message might be a bit of a challenge but I will update this section once I have a solution. If I may ask:: are you looking at a python only solution ?

Upvotes: 0

Bobby
Bobby

Reputation: 1102

For your second requirement, could the account be a shared inbox?

Here is the code for the rest:

import win32com.client

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

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

Upvotes: 1

Related Questions