HHeckner
HHeckner

Reputation: 5056

Use Redemption (Outlook 2010) to get ContactInfo of each Recipient of a Mail

I use the following code to get ContactInfo (in Outlook2010) of each recipient of a mail to be sent. The code works, but only for a few contacts, although all contacts are stored in my adressbook. For some the last line (GetContact) delivers Nothing. Why?

' Create RDO session 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

Upvotes: 0

Views: 488

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

GetContact in both Outlook Object Model and Redemption relies on the entry id being of OAB type. On the incoming messages, all SMTP recipients have one-off entry id (it does not point to any existing address book objects and embeds name, address and address type inside).

In general, you will need to extract the recipient address, then search the Contacts folder for a matching contact based on email1, email2 or email3 values.

Upvotes: 1

Related Questions