6

I want to get the SenderEmailAddress of all email sent on two specified mail addresses : 123@abc.com and 456@def.com 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 :

123@abc.com

  • -> Inbox

&

456@def.com

  • -> 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 123@abc.com Inbox
inbox = outlook.GetDefaultFolder(6).Folders[2] # To access 456@def.com 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 !

David G
  • 63
  • 1
  • 3

1 Answers1

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('123@abc.com').Folders('Inbox') # To access 123@abc.com Inbox
inbox = outlook.Folders('456@def.com').Folders('Inbox') # To access 456@def.com Inbox
drec4s
  • 7,946
  • 8
  • 33
  • 54
  • 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 ! – David G May 18 '18 at 08:05
  • 1
    For anyone who finds this after me it appears the format for referencing folders/subfolders has updated to `inbox = outlook.Folders['123@abc.com'].Folders['Inbox']` – Jeremiah Haremza Feb 08 '21 at 13:57