Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Outlook: Read Inbox of additional mailbox

I'm using Outlook 2010 - and have my main mailbox: [email protected]

I have also added another mailbox to my profile: mb data proc

Both appear as top level folders within Outlook:

[email protected]
-Inbox
-Sent Items
-Deleted Items

mb data proc
-Inbox
-Sent Items
-Deleted Items

I cannot create a different profile for the additional mailbox. It has been added in the same profile.

How do I get a reference to the Inbox in the "mb data proc" mailbox?

This is the same problem as described here Get reference to additional Inbox but this in VBS.

How to do in python?

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder=outlook.Folders("mb data proc")
msg=folder.Items
msgs=msg.GetLast()
print msgs    

I tried this but I get this error:

       folder=outlook.Folders("mb data proc")
AttributeError: _Folders instance has no __call__ method
like image 462
heycooldude Avatar asked Apr 08 '14 09:04

heycooldude


People also ask

How do you open a second mailbox in Outlook?

On the Outlook on the web navigation bar, click your name. A list appears. Click Open another mailbox. Type the email address of the other mailbox that you want to open, and then click Open.


2 Answers

I had a similar doubt and as I understand it the solution stated here is for Python 2.7

I will try to make it understandable regarding how to operate it using Python 3.+ versions.

import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders.Item("Mailbox Name")
inbox = folder.Folders.Item("Inbox")
msg = inbox.Items
msgs = msg.GetLast()
print (msgs)
print (msgs.Subject)

Since _Folder is not callable, you need to use Folders.Item() method in Python 3+ to reference your mailbox.

Hope that was helpful. Thanks!

like image 122
Mohanty.pyt Avatar answered Sep 29 '22 18:09

Mohanty.pyt


Here's a simple solution. I think the only part you missed was getting to the "Inbox" folder inside of "mb data proc".

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder = outlook.Folders("mb data proc")
inbox = folder.Folders("Inbox")
msg = inbox.Items
msgs = msg.GetLast()
print msgs
like image 36
tkd-ee Avatar answered Sep 29 '22 19:09

tkd-ee