[英]How to access cc email address from email items from outlook using python and win32com.client
I am trying to access email addresses of cc recipients of mails in my outlook using python我正在尝试使用 python 在我的 Outlook 中访问邮件抄送收件人的电子邮件地址
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. messages.Item(9).cc
返回抄送地址名称,但无法检索电子邮件地址。
Use the Recipients property to get the CC recipients.使用Recipients属性获取抄送收件人。 The property returns a
Recipients
collection that represents all the recipients for the Outlook item.该属性返回一个
Recipients
集合,该集合代表 Outlook 项目的所有收件人。 To find the CC recipients you can check the Type
property of the Recipient
class in the following way:要查找抄送收件人,您可以通过以下方式检查
Recipient
类的Type
属性:
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
.获得 CC 收件人对象后,您可以检查Recipient.Address属性,该属性返回一个表示
Recipient
电子邮件地址的字符串。
Also you may check the Recipient.AddressEntry property which returns the AddressEntry
object corresponding to the resolved recipient.您还可以检查Recipient.AddressEntry属性,该属性返回对应于已解析收件人的
AddressEntry
对象。 So, you will be able to distinguish Exchange users and etc. For example:因此,您将能够区分 Exchange 用户等。例如:
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.如果
AddressEntry
属于诸如全局地址列表 (GAL) 之类的 Exchange AddressList
对象并且对应于 Exchange 用户,则AddressEntry.GetExchangeUser方法返回一个表示AddressEntry
的ExchangeUser
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.