共用方式為


顯示郵件寄件者位址專案詳細資料

傳輸提供者所傳遞之每個郵件訊息的收件者,都有提供者為工作階段所提供之通訊錄階層的地址項目。 這個主題會說明如何以程式方式顯示目前查閱程式中所顯示郵件項目之寄件者的地址項目資訊。

  1. 對於目前顯示的郵件項目,使用 PropertyAccessor 物件判斷寄件者的項目 ID。

  2. 使用目前工作階段的 NameSpace.GetAddressEntryFromID 方法傳回 AddressEntry 物件。

  3. 使用 AddressEntry.AddressEntryUserType 屬性判斷 AddressEntry 的類型,然後依此顯示詳細資料:

    • 如果位址專案是 Outlook 連絡人資料夾中的連絡人項目,或寄件者的 SMTP 位址符合預設 [連絡人] 資料夾中一個連絡人項目的電子郵件地址,則會在 [連絡人] 偵測器中顯示位址專案資訊。 若要比對 [連絡人] 資料夾中的電子郵件地址,請使用 Table 物件來快速篩選該資料夾中專案的 ContactItem.Email1AddressContactItem.Email2AddressContactItem.Email3Address 屬性。
  • 在所有其他情況下,請在 [Email屬性] 對話方塊中顯示位址專案資訊。

註解

若要執行這個程式碼範例:

  1. 開啟郵件訊息,以顯示在作用中查閱程式。

  2. 將程式碼放置在內建的 ThisOutlookSession 模組中。

  3. 執行程式, TestAddressEntryDetails 以在作用中的偵測器中顯示郵件訊息的位址專案詳細資料:

Sub TestAddressEntryDetails() 
 Dim oMail As MailItem 
 
 Set oMail = Application.ActiveInspector.CurrentItem 
 DisplayAddressEntryDetails oMail 
End Sub 
 
 
Sub DisplayAddressEntryDetails(oM As MailItem) 
 Dim oPA As Outlook.PropertyAccessor 
 Dim oContact As Outlook.ContactItem 
 Dim oSender As Outlook.AddressEntry 
 Dim SenderID As String 
 
 'Create an instance of PropertyAccessor 
 Set oPA = oM.PropertyAccessor 
 
 'Obtain PidTagSenderEntryId and convert to string 
 SenderID = oPA.BinaryToString _ 
 (oPA.GetProperty("https://schemas.microsoft.com/mapi/proptag/0x0C190102")) 
 
 'Obtain AddressEntry Object of the sender 
 Set oSender = Application.Session.GetAddressEntryFromID(SenderID) 
 
 'Examine AddressEntryUserType 
 If oSender.AddressEntryUserType = olOutlookContactAddressEntry Then 
 'Obtain ContactItem for AddressEntry 
 Set oContact = oSender.GetContact 
 oContact.Display 
 'Display details for Exchange or SMTP sender 
 Else 
 oSender.Details 
 End If 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應