Search code examples
vstooutlook-addin

Getting email address from a Recipient object


I’m developing a VSTO addin which needs to read all the email address when a new email is being sent out. Below is the code I’m using right now but it is not working in few cases.

                            if (addr.Type == "EX")
                            {
                               if (addr.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry
                                    || addr.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                                {
                                    exch = addr.GetExchangeUser();
                                    smtpAddress = exch != null ? exch.PrimarySmtpAddress : null;
                                }
                                else if (addr.AddressEntryUserType == OlAddressEntryUserType.olOutlookContactAddressEntry)
                                {
                                    cont = addr.GetContact();
                                    //returns the actual contact but it has 3 email properties (Email1Address, Email2Address, Email3Address). 
  //How to identify which email has the user selected
                                }
                            }
                            else if (addr.Type == "SMTP")
                            {
                                smtpAddress = addr.Address;
                            }

If the AddressEntryUserType is olExchangeUserAddressEntry or olExchangeRemoteUserAddressEntry then the code is working fine. But if it is a local outlook contact (olOutlookContactAddressEntry) I’m not sure on how to retrive the email address. The GetContact method gives me the actual contact but since it has 3 emails I don’t know on how to find which address has the user choosen while composing the email.

I have already tried converting the Exchange based email address to SMTP as discussed on this forum. But it is giving a huge performance impact. It takes around 300ms for one addres to be converted to SMTP. Is there any other efficient way to identify the email address from a Recepient object?


Solution

  • The selected index is embedded in the OAB entry id - check that the first 20 bytes are 0x00,0x00,0x00,0x00,0xFE,0x42,0xAA,0x0A,0x18,0xC7,0x1A,0x10,0xE8,0x85,0x0B,0x65,0x1C,0x24,0x00,0x00 Byte 25 is type (0x5 is DL, 0x4 is contact). Byte 29 is index (for contact only): 0 = email1, 1 = email2, 2 = email3, 3 = business fax, 4 = home fax, 5 = other fax.