View Single Post
  #4  
Old March 4th 10, 02:10 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Get recipient's email address

I'd probably check for "cn=" rather than "@", but "@" will probably work.

You need to use PR_SMTP_ADDRESS when it's not cached mode and use
PR_EMS_AB_PROXY_ADDRESSES when it is. You can check that using
ExchangeConnectionMode and interpreting the result as a member of the
OlExchangeConnectionMode enum. If it's one f the cached settings you use
PR_EMS_AB_PROXY_ADDRESSES. Some of them indicate you won't get a result
(disconnected or offline).

PR_EMS_AB_PROXY_ADDRESSES is what's known as a PR_MV_STRING8 property, it's
an array of strings. There may be 1 or more entries there but you have to
get the results of reading the property as a string array and parse the
array. A result with a capitalized "SMTP:" is the default SMTP address, any
with "smtp:" are alternates.

In addition, I'm not sure if PR_EMS_AB_PROXY_ADDRESSES will compile with the
declaration as it is. You might have to use this construct for the
declaration:

const int PR_EMS_AB_PROXY_ADDRESSES = unchecked((int)0x800F101E);

One tip, if you plan to do a lot with things like DASL and MAPI property
tags you might want to get a MAPI viewer. MFCMAPI is a free one from MS, I
personally use OutlookSpy (www.dimastr.com). A viewer will show the
properties of items, folders, stores, etc. and will show the prop tags for
you.

Another tip is what I said earlier. Avoid concatenated dot operators. They
create internal objects that you cannot explicitly release, which can lead
to memory leaks and other problems. Instead of something like
mail.Recipients[1].Address, use an explicit Recipients collection and an
explicit Recipient object. That way you can release the objects as needed
and when in loops avoid the 256 RPC channel errors. You also always declare
COM objects outside of loops for the same reason: only 1 object created and
you can explicitly release it as needed.

--
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
...
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;
}
}
}


Ads