简体   繁体   中英

Get email address of a recipient in Outlook VSTO + Read MailTips

I'm currently having issues with an Outlook add-in created for 2010 with VSTO that i developed with identifying if an email address is located inside the organization or is located outside the organization.

While an email is being sent out i'm using the below MAPI property to read the email address of the recipient. Where addr is the AddressEntry object.

Microsoft.Office.Interop.Outlook.PropertyAccessor pa = addr.PropertyAccessor;
smtpAddress = pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E").ToString();

This works fine for the exchange contacts and the local contacts. But if you create a local contact and choose the email address from the Global Address Book then this MAPI property is not present in that particular contact. I just need to know what will be the best way to find if a contact (email address) is inside the organization or outside the organization (Also this method reduces the performance, there are people in my organization who would send email to more than 500 users at a time and it is taking more than 10 minutes to process the internal/external email scan through the above MAPI property). I know that outlook already displays the same information as a MailTip on the "New Email" window. So my question is

  1. Is there any way to tap into the MailTip and read the information from it?

  2. If no what would be the best way to find if the contact email address is inside/outside the organization (Considering the performance)

The Outlook object model doesn't provide anything for reading MailTips.

Try to use the following code instead:

private string GetSenderSMTPAddress(Outlook.MailItem mail)
{
    string PR_SMTP_ADDRESS =
       @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
    if (mail == null)
    {
        throw new ArgumentNullException();
    }
    if (mail.SenderEmailType == "EX")
    {
       Outlook.AddressEntry sender =
          mail.Sender;
       if (sender != null)
       {
           //Now we have an AddressEntry representing the Sender
           if (sender.AddressEntryUserType ==
               Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry
               || sender.AddressEntryUserType ==                    Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
           {
               //Use the ExchangeUser object PrimarySMTPAddress
               Outlook.ExchangeUser exchUser =
                   sender.GetExchangeUser();
               if (exchUser != null)
               {
                   return exchUser.PrimarySmtpAddress;
               }
               else
               {
                   return null;
               }
           }
           else
           {
               return sender.PropertyAccessor.GetProperty(
                   PR_SMTP_ADDRESS) as string;
           }
       }
       else
       {
           return null;
       }
   }
   else
   {
       return mail.SenderEmailAddress;
   }
}

See How to: Get the SMTP Address of the Sender of a Mail Item . Also you may find the HowTo: Convert Exchange-based email address into SMTP email address article helpful.

Mail tips can be accessed using EWS only - see https://msdn.microsoft.com/en-us/library/office/dd877060%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396

If using Redemption is an option, it exposes RDOAddressEntry . GetMailtips method that returns RDOMailTips object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM