6

I want to get the SenderEmailAddress of all email sent on two specified mail addresses : [email protected] and [email protected] that are in my Outlook Application on my computer, the point is to make a list of all mail senders that will be kept in a csv file.

The architectures of these mailboxes are this way :

[email protected]

  • -> Inbox

&

[email protected]

  • -> Inbox

I would like to read the Inbox Folders from the two mailboxes and store the SenderEmailAddress from the two Folders

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

I've found that for some people it works to use

inbox = outlook.GetDefaultFolder(6).Folders[1] # To access [email protected] Inbox
inbox = outlook.GetDefaultFolder(6).Folders[2] # To access [email protected] Inbox

But in my case it just gets me inside of the two subfolders that are inside of Inbox and nothing more, I don't have the possibility to access at all to the second mailbox. I have the possibility to detect these Mailboxes by using

for folder in outlook.Folders: 
    print(folder.Name)

I have no idea how to fix this and finally access to my second mail address, if anyone would be capable to help me on this it would be great.

Thanks !

1 Answer 1

11

That happens because GetDefaultFolder(6) is referencing to the first Inbox, thus .Folders[1] and .Folders[2] will only get you to the subfolders of that same first Inbox.

You can access those inboxes by specifying them like this:

inbox = outlook.Folders('[email protected]').Folders('Inbox') # To access [email protected] Inbox
inbox = outlook.Folders('[email protected]').Folders('Inbox') # To access [email protected] Inbox
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly ! I thought that GetDefaultFolder(6) was for getting into 'Inbox', I didn't know that I had to use Folders twice, thanks a lot for your answer man !
For anyone who finds this after me it appears the format for referencing folders/subfolders has updated to inbox = outlook.Folders['[email protected]'].Folders['Inbox']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.