4
votes

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

1 Answers

5
votes

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