0

我使用以下代码获取要发送的邮件的每个收件人的 ContactInfo(在 Outlook2010 中)。该代码有效,但仅适用于少数联系人,尽管所有联系人都存储在我的地址簿中。对于某些人来说,最后一行 (GetContact) 没有提供任何内容。为什么?

' 创建 RDO 会话 Dim session Set session = CreateObject("Redemption.RDOSession")

Set session.MAPIOBJECT = Application.session.MAPIOBJECT

' Get current email

ActiveInspector.CurrentItem.Save ' Necessary to get current status
Dim mail
Set mail = session.GetMessageFromID(ActiveInspector.CurrentItem.EntryID)

' Create salutation line
Dim salutationLine As String
salutationLine = ""

For Each Recipient In mail.Recipients
    ' Skip CC and BCC addresses
    If (Recipient.Type <> olTo) Then GoTo NextRecipient

    ' Assume standard salutation and use complete name as first name
    Dim salutationType As String
    salutationType = ""
    Dim firstName As String
    Dim lastName As String
    Dim recipientName As String

    recipientName = IIf(Recipient.Name <> "", Recipient.Name, Recipient.Address)
    lastName = ""

    If InStr(1, recipientName, " ") > 0 Then
        firstName = Split(recipientName, " ")(0)
        lastName = Split(recipientName, " ")(1)
    End If
    Dim addressEntry
    Set addressEntry = Recipient.addressEntry
    If (Not addressEntry Is Nothing) Then
        ' If we have qualified name information: extract first and last name
        If (addressEntry.firstName <> "") Then firstName = addressEntry.firstName
        If (addressEntry.lastName <> "") Then lastName = addressEntry.lastName

        Dim contactInfo
        Set contactInfo = addressEntry.GetContact()



        If (Not contactInfo Is Nothing) Then
4

1 回答 1

1

Outlook 对象模型和兑换中的 GetContact 依赖于 OAB 类型的条目 ID。在传入的消息中,所有 SMTP 收件人都有一次性的条目 ID(它不指向任何现有的通讯簿对象,并且在其中嵌入名称、地址和地址类型)。

通常,您需要提取收件人地址,然后根据 email1、email2 或 email3 值在联系人文件夹中搜索匹配的联系人。

于 2013-10-18T23:32:24.700 回答