Reputation: 664
Problem: I have a list of email addresses of employees in my company. I want to store the email address of their boss/leader(called "Reports to" in Outlook Organization tab).
Info: I want to use Python 3.x to resolve the issue. Best would be to use win32.Dispatch('outlook.application') or similar that not require Active Directory admin intervention.
Screenshot from outlook:
The solution:
I found the solution after reading Eugene Astafiev's post below. Thanks a lot!
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
gal = outlook.Session.GetGlobalAddressList()
entries = gal.AddressEntries
recipient = outlook.CreateRecipient("[email protected]")
recipient.Resolve()
print ("recipient:", recipient)
print ("recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager():", recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager())
print ("recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager().PrimarySmtpAddress:", recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager().PrimarySmtpAddress)
Upvotes: 1
Views: 851
Reputation: 49405
You can use the GetExchangeUserManager method of the ExchangeUser
class from the Outlook object model. The sequence of property and method calls looks in the following way:
Recipient.AddressEntry.GetExchangeUser().GetExchangeUserManager()
ExchangeUser
is derived from the AddressEntry
object, and is returned instead of an AddressEntry
when the caller performs a query interface on the AddressEntry
object.
This object provides first-class access to properties applicable to Exchange users such as FirstName
, JobTitle
, LastName
, and OfficeLocation
. You can also access other properties specific to the Exchange user that are not exposed in the object model through the PropertyAccessor
object. Note that some of the explicit built-in properties are read-write properties. Setting these properties requires the code to be running under an appropriate Exchange administrator account; without sufficient permissions, calling the ExchangeUser.Update
method will result in a "permission denied" error.
Upvotes: 2
Reputation: 66255
Assuming you already have an instance of the AddressEntry
object, use AddressEntry.GetExchangeUser().Manager
(returns another AddressEntry
object, be prepared to handle nulls and errors).
Upvotes: 0