简体   繁体   English

如何使用 python 和 win32com.client 从 Outlook 的电子邮件项目中访问 c​​c 电子邮件地址

[英]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方法返回一个表示AddressEntryExchangeUser对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 想从 Python 发送一个 Outlook email 和 win32com.client 从另一个 email 地址默认 email 地址 - Want to send an Outlook email from Python with win32com.client from a other email address that default email address 如何通过Outlook使用其他邮件来源发送HTML电子邮件(win32com.client) - How to send HTML email through Outlook with a different mail-from (win32com.client) 使用 python 库 win32com.client 在没有任何许可的情况下发送 Outlook 电子邮件 - Send an outlook email without any permission using python library win32com.client 如何在 Python 中使用 win32com.client 保存 Outlook 中的附件? - How to save attachment from outlook using win32com.client in Python? 尝试使用Python从Outlook 2007发送邮件(win32com.client) - Trying to send a mail from Outlook 2007 using Python (win32com.client) Python win32com.client - 只有当我打开 Outlook 时电子邮件才会发出 - Python win32com.client - Email only goes out when I have outlook open Python win32com.client和outlook - Python win32com.client and outlook Python win32com.client发送电子邮件中嵌入的图像 - Python win32com.client send image embedded in email 使用 Python Win32Com.Client 发送电子邮件发送错误 - Sending Email with Python Win32Com.Client Send Error 使用win32com.client向自己发送电子邮件 - Send myself an email using win32com.client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM