使用Redemption(Outlook 2010)获取邮件的每个收件人的ContactInfo

时间:2013-10-18 12:27:01

标签: email outlook-2010 outlook-redemption

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

'创建RDO会话     昏暗的会议     设置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

1 个答案:

答案 0 :(得分:1)

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

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