View Single Post
  #3  
Old March 4th 10, 05:06 AM posted to microsoft.public.outlook.program_addins
Mark B[_2_]
external usenet poster
 
Posts: 93
Default Get recipient's email address

I haven't got Exchange here to test it out on so if you can see anything
wrong with the following code I'd be grateful for any corrections:


namespace MyApp1.GetRecipientEmailAddress
{
class cGetRecipientEmailAddress
{
const int PR_SMTP_ADDRESS = 0x39FE001E;
const int PR_EMS_AB_PROXY_ADDRESSES = (int) 0x800F101E;

/// summary
/// Get recipient email address in format even if on
Exchange.
/// /summary
/// returns/returns
public string
mGetEmailAddress(Microsoft.Office.Interop.Outlook. Recipients objRecipients)
{

//See if normal email address
if (objRecipients[1].Address.Contains("@"))
{
return objRecipients[1].Address;
}

//See if Exchange user has email address
string strExchangeSMTPEmailAddress
=objRecipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress ;
if (strExchangeSMTPEmailAddress.Contains("@"))
{
return strExchangeSMTPEmailAddress;
}

//Access MAPI property
string
strMAPIEmailAddress=objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"+
PR_SMTP_ADDRESS.ToString()) as string;
if (strMAPIEmailAddress.Contains("@"))
{
return strMAPIEmailAddress;
}

//Access MAPI property (proxy)
string strMAPIEmailAddressProxy =
objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
+ PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string;
if (strMAPIEmailAddressProxy.Contains("@"))
{
return strMAPIEmailAddressProxy;
}

//Return null
return null;
}
}
}



"Ken Slovak - [MVP - Outlook]" wrote in message
...
Yes, that's an Exchange DN type address (an Exchange Distinguished Name).

If the recipient is in the GAL or a contact item you can use this type of
code to get at the SMTP address:

string recipSMTP =
mail.Recipients[1].AddressEntry.GetExchangeUser.PrimarySmtpAddress;

Otherwise you need to access some MAPI properties using PropertyAccessor.
Which property to access depends on whether or not cached Exchange mode is
being used or not. If a direct connection is used you can get the
Recipient.AddressEntry.PropertyAccessor object and use the PR_SMTP_ADDRESS
property tag with it, if cached mode is used you would need to use the
PR_EMS_AB_PROXY_ADDRESSES property tag.

const int PR_SMTP_ADDRESS = 0x39FE001E;
const int PR_EMS_AB_PROXY_ADDRESSES = 0x800F101E;

For use with PropertyAccessor you would use a DASL property tag, which
would look like this:

"http://schemas.microsoft.com/mapi/proptag/" + PR_SMTP_ADDRESS.ToString();
// or the other tag

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Mark B" wrote in message
...
VSTO, OL2007, C#

From our Add-in, most of the time mail.Recipients[1].Address works to
return the recipients email address as say

However, I noticed the following was returned for
mail.Recipients[1].Address this morning from one site instead of an email
address:

/O=COMPANY1/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=SMITH

I assume it has got something to do with the user being on exchange? Is
there anyway to simply get the email address?




Ads