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?