1

I am trying to access email addresses of cc recipients of mails in my outlook using python

import win32com.client
#initate the outllok application
outlook = win32com.client.Dispatch('outlook.application')
#read outllok inbox message 
inbox = outlook.GetNamespace('MAPI')
inbox = inbox.GetDefaultFolder(6)
messages = inbox.Items

messages.Item(9).cc returns cc addresses names but not able to retrieve email addresses.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • https://stackoverflow.com/questions/33767792/accessing-email-recipient-addresses-from-outlook-using-python this should help – Skul9 Jun 03 '22 at 15:43

1 Answers1

0

Use the Recipients property to get the CC recipients. The property returns a Recipients collection that represents all the recipients for the Outlook item. To find the CC recipients you can check the Type property of the Recipient class in the following way:

myRecipient.Type = olCC

After you have got the CC recipient object you could check the Recipient.Address property which returns a string representing the email address of the Recipient.

Also you may check the Recipient.AddressEntry property which returns the AddressEntry object corresponding to the resolved recipient. So, you will be able to distinguish Exchange users and etc. For example:

Sub DemoAE() 
 Dim colAL As Outlook.AddressLists 
 Dim oAL As Outlook.AddressList 
 Dim colAE As Outlook.AddressEntries 
 Dim oAE As Outlook.AddressEntry 
 Dim oExUser As Outlook.ExchangeUser 
 
 Set colAL = Application.Session.AddressLists 
 For Each oAL In colAL 
   'Address list is an Exchange Global Address List 
   If oAL.AddressListType = olExchangeGlobalAddressList Then 
     Set colAE = oAL.AddressEntries 
     For Each oAE In colAE 
       If oAE.AddressEntryUserType = olExchangeUserAddressEntry Then 
         Set oExUser = oAE.GetExchangeUser 
         Debug.Print(oExUser.JobTitle) 
         Debug.Print(oExUser.OfficeLocation) 
         Debug.Print(oExUser.BusinessTelephoneNumber) 
       End If 
     Next 
   End If 
 Next 
End Sub

The AddressEntry.GetExchangeUser method returns an ExchangeUser object that represents the AddressEntry if the AddressEntry belongs to an Exchange AddressList object such as the Global Address List (GAL) and corresponds to an Exchange user.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45