[英]Want to send an Outlook email from Python with win32com.client from a other email address that default email address
[英]How to access cc email address from email items from outlook using python and win32com.client
我正在嘗試使用 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
返回抄送地址名稱,但無法檢索電子郵件地址。
使用Recipients屬性獲取抄送收件人。 該屬性返回一個Recipients
集合,該集合代表 Outlook 項目的所有收件人。 要查找抄送收件人,您可以通過以下方式檢查Recipient
類的Type
屬性:
myRecipient.Type = olCC
獲得 CC 收件人對象后,您可以檢查Recipient.Address屬性,該屬性返回一個表示Recipient
電子郵件地址的字符串。
您還可以檢查Recipient.AddressEntry屬性,該屬性返回對應於已解析收件人的AddressEntry
對象。 因此,您將能夠區分 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
如果AddressEntry
屬於諸如全局地址列表 (GAL) 之類的 Exchange AddressList
對象並且對應於 Exchange 用戶,則AddressEntry.GetExchangeUser方法返回一個表示AddressEntry
的ExchangeUser
對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.