Get recipient's email address

Status
Not open for further replies.
M

Mark B

VSTO, OL2007, C#

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

the recipients email address as say joe.smith@company.com

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?
 
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

"Mark B" <none123@none.com> wrote in message

news:ezI0PlnuKHA.4636@TK2MSFTNGP06.phx.gbl...
> VSTO, OL2007, C#

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

> 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?

>
 
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 a@b.com 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;

}

}

}
<kenslovak@mvps.org> wrote in message

news:%23BvUJkuuKHA.3408@TK2MSFTNGP06.phx.gbl...
> 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

> >

>

> "Mark B" <none123@none.com> wrote in message
> news:ezI0PlnuKHA.4636@TK2MSFTNGP06.phx.gbl...
> > VSTO, OL2007, C#
>

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

>> 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?
>

>>

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

"Mark B" <none123@none.com> wrote in message

news:%23i0zmh1uKHA.6124@TK2MSFTNGP04.phx.gbl...
> 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 a@b.com 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;
> }
> }
> }
>
 
Hopefully below will work. I tried to remove all dot concatenation but think you might be referring to my earlier code.

using Outlook=Microsoft.Office.Interop.Outlook;

namespace MYAPP.GetRecipientEmailAddress

{

class cGetRecipientEmailAddress

{

const int PR_SMTP_ADDRESS = 0x39FE001E;

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

/// <summary
/// Get recipient email address in a@b.com format even if on Exchange.

/// </summary
/// <returns></returns
public string mGetEmailAddress(Outlook.Recipients objRecipients)

{

//See if normal email address

if (objRecipients[1].Address.Contains("@"))

{

return objRecipients[1].Address;

}

//See if Exchange user is in GAL or contact item and has email address

string strExchangeSMTPEmailAddress = "";

try

{

strExchangeSMTPEmailAddress = objRecipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress;

}

catch { }

if (strExchangeSMTPEmailAddress.Contains("@"))

{

return strExchangeSMTPEmailAddress;

}

//Not in GAL, try to access MAPI property

switch (fIsInExchangeCachedMode())

{

case false: //Direct Mode

{

string strMAPIEmailAddress = "";

try

{

strMAPIEmailAddress = objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/" + PR_SMTP_ADDRESS.ToString()) as string;

}

catch { }

if (strMAPIEmailAddress.Contains("@"))

{

return strMAPIEmailAddress;

}

break;

}

case true: //Cached Mode

{

//Access MAPI property (proxy)

string[] strMAPIEmailAddressProxy = null;

try

{

strMAPIEmailAddressProxy = objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/" + PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];

foreach (string strItem in strMAPIEmailAddressProxy)

{

if (strItem.Contains("SMTP:") && strItem.Contains("@"))

{

strItem.Replace("SMTP:", "");

strItem.Trim();

return strItem;

}

}

}

catch { }

break;

}

}

return null;

}

/// <summary
/// Returns True if in Exchange Cached Mode

/// </summary
/// <returns></returns
public bool fIsInExchangeCachedMode()

{

switch (Globals.ThisAddIn.Application.Session.ExchangeConnectionMode)

{

case Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedConnectedFull: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedDisconnected: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedOffline: { return true;}

case Outlook.OlExchangeConnectionMode.olNoExchange: { break; }

case Outlook.OlExchangeConnectionMode.olOffline: { break; }

case Outlook.OlExchangeConnectionMode.olOnline:{ break; }

}

return false;

}

}

}
<kenslovak@mvps.org> wrote in message news:uYfBxR6uKHA.5036@TK2MSFTNGP02.phx.gbl...
> 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.

> >

>

> "Mark B" <none123@none.com> wrote in message
> news:%23i0zmh1uKHA.6124@TK2MSFTNGP04.phx.gbl...
> >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 a@b.com 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;
> > }
> > }
> > }
> >

>
 
Hopefully the code below will work. I tried to remove all dot concatenation

but think you might be referring to my earlier code.

using Outlook=Microsoft.Office.Interop.Outlook;

namespace MYAPP.GetRecipientEmailAddress

{

class cGetRecipientEmailAddress

{

const int PR_SMTP_ADDRESS = 0x39FE001E;

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

/// <summary
/// Get recipient email address in a@b.com format even if on

Exchange.

/// </summary
/// <returns></returns
public string mGetEmailAddress(Outlook.Recipients objRecipients)

{

//See if normal email address

if (objRecipients[1].Address.Contains("@"))

{

return objRecipients[1].Address;

}

//See if Exchange user is in GAL or contact item and has email

address

string strExchangeSMTPEmailAddress = "";

try

{

strExchangeSMTPEmailAddress =

objRecipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress;

}

catch { }

if (strExchangeSMTPEmailAddress.Contains("@"))

{

return strExchangeSMTPEmailAddress;

}

//Not in GAL, try to access MAPI property

switch (fIsInExchangeCachedMode())

{

case false: //Direct Mode

{

string strMAPIEmailAddress = "";

try

{

strMAPIEmailAddress =

objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"

+ PR_SMTP_ADDRESS.ToString()) as string;

}

catch { }

if (strMAPIEmailAddress.Contains("@"))

{

return strMAPIEmailAddress;

}

break;

}

case true: //Cached Mode

{

//Access MAPI property (proxy)

string[] strMAPIEmailAddressProxy = null;

try

{

strMAPIEmailAddressProxy =

objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"

+ PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];

foreach (string strItem in

strMAPIEmailAddressProxy)

{

if (strItem.Contains("SMTP:") &&

strItem.Contains("@"))

{

strItem.Replace("SMTP:", "");

strItem.Trim();

return strItem;

}

}

}

catch { }

break;

}

}

return null;

}

/// <summary
/// Returns True if in Exchange Cached Mode

/// </summary
/// <returns></returns
public bool fIsInExchangeCachedMode()

{

switch

(Globals.ThisAddIn.Application.Session.ExchangeConnectionMode)

{

case

Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedConnectedFull:

{ return true;}

case

Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders: { return true;}

case Outlook.OlExchangeConnectionMode.olCachedDisconnected:

{ return true;}

case Outlook.OlExchangeConnectionMode.olCachedOffline: {

return true;}

case Outlook.OlExchangeConnectionMode.olNoExchange: {

break; }

case Outlook.OlExchangeConnectionMode.olOffline: { break; }

case Outlook.OlExchangeConnectionMode.olOnline:{ break; }

}

return false;

}

}

}
 
Hi:

I guess the answer is sitting next to this post. Buy a Redemption

component.It saves me a lot of time.

Cheers,

Danny

"Mark B" <none123@none.com> wrote in message

news:ezI0PlnuKHA.4636@TK2MSFTNGP06.phx.gbl...
> VSTO, OL2007, C#

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

> 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?

>
 
Did you have a question, or are you showing your solution for the problem?

"Mark B" <none123@none.com> wrote in message

news:%23RN2YpBvKHA.3536@TK2MSFTNGP06.phx.gbl...
> Hopefully the code below will work. I tried to remove all dot
> concatenation but think you might be referring to my earlier code.

> using Outlook=Microsoft.Office.Interop.Outlook;

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

> /// <summary
> /// Get recipient email address in a@b.com format even if on
> Exchange.
> /// </summary
> /// <returns></returns
> public string mGetEmailAddress(Outlook.Recipients objRecipients)
> {

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

> //See if Exchange user is in GAL or contact item and has email
> address
> string strExchangeSMTPEmailAddress = "";
> try
> {
> strExchangeSMTPEmailAddress =
> objRecipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress;
> }
> catch { }

> if (strExchangeSMTPEmailAddress.Contains("@"))
> {
> return strExchangeSMTPEmailAddress;
> }

> //Not in GAL, try to access MAPI property
> switch (fIsInExchangeCachedMode())
> {
> case false: //Direct Mode
> {
> string strMAPIEmailAddress = "";
> try
> {
> strMAPIEmailAddress =
> objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
> + PR_SMTP_ADDRESS.ToString()) as string;
> }
> catch { }

> if (strMAPIEmailAddress.Contains("@"))
> {
> return strMAPIEmailAddress;
> }
> break;
> }

> case true: //Cached Mode
> {
> //Access MAPI property (proxy)
> string[] strMAPIEmailAddressProxy = null;

> try
> {
> strMAPIEmailAddressProxy =
> objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
> + PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];
> foreach (string strItem in
> strMAPIEmailAddressProxy)
> {
> if (strItem.Contains("SMTP:") &&
> strItem.Contains("@"))
> {
> strItem.Replace("SMTP:", "");
> strItem.Trim();
> return strItem;
> }
> }
> }
> catch { }
> break;
> }
> }
> return null;
> }

> /// <summary
> /// Returns True if in Exchange Cached Mode
> /// </summary
> /// <returns></returns
> public bool fIsInExchangeCachedMode()
> {
> switch
> (Globals.ThisAddIn.Application.Session.ExchangeConnectionMode)
> {
> case
> Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle: { return true;}
> case
> Outlook.OlExchangeConnectionMode.olCachedConnectedFull: { return true;}
> case
> Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders: { return true;}
> case Outlook.OlExchangeConnectionMode.olCachedDisconnected:
> { return true;}
> case Outlook.OlExchangeConnectionMode.olCachedOffline: {
> return true;}
> case Outlook.OlExchangeConnectionMode.olNoExchange: {
> break; }
> case Outlook.OlExchangeConnectionMode.olOffline: { break; }
> case Outlook.OlExchangeConnectionMode.olOnline:{ break; }
> }
> return false;
> }
> }
> }
>
 
Apologies. I was just showing it in case anyone saw something wrong with it

since my testing here is a bit limited since I don't have Exchange.

My assumption with this particular block of code here is that the format of

the string elements in PR_EMS_AB_PROXY_ADDRESSES is:

"SMTP:joe@company1.com"

"smtp:fred@company2.com"

since I extract the SMTP: bit. If that's not the case please let me know.

case true: //Cached Mode

{

//Access MAPI property (proxy)

string[] strMAPIEmailAddressProxy = null;

try

{

strMAPIEmailAddressProxy =

objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"

+ PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];

foreach (string strItem in

strMAPIEmailAddressProxy)

{

if (strItem.Contains("SMTP:") &&

strItem.Contains("@"))

{

strItem.Replace("SMTP:", "");

strItem.Trim();

return strItem;

}

}

}

catch { }

break;
<kenslovak@mvps.org> wrote in message

news:ubBd15GvKHA.5940@TK2MSFTNGP02.phx.gbl...
> Did you have a question, or are you showing your solution for the problem?

> >

>

> "Mark B" <none123@none.com> wrote in message
> news:%23RN2YpBvKHA.3536@TK2MSFTNGP06.phx.gbl...
> > Hopefully the code below will work. I tried to remove all dot
> > concatenation but think you might be referring to my earlier code.
>

>> using Outlook=Microsoft.Office.Interop.Outlook;
>

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

>> /// <summary
>> /// Get recipient email address in a@b.com format even if on
> > Exchange.
> > /// </summary
>> /// <returns></returns
>> public string mGetEmailAddress(Outlook.Recipients objRecipients)
> > {
>

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

>> //See if Exchange user is in GAL or contact item and has email
> > address
> > string strExchangeSMTPEmailAddress = "";
> > try
> > {
> > strExchangeSMTPEmailAddress =
> > objRecipients[1].AddressEntry.GetExchangeUser().PrimarySmtpAddress;
> > }
> > catch { }
>

>> if (strExchangeSMTPEmailAddress.Contains("@"))
> > {
> > return strExchangeSMTPEmailAddress;
> > }
>

>> //Not in GAL, try to access MAPI property
> > switch (fIsInExchangeCachedMode())
> > {
> > case false: //Direct Mode
> > {
> > string strMAPIEmailAddress = "";
> > try
> > {
> > strMAPIEmailAddress =
> > objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
> > + PR_SMTP_ADDRESS.ToString()) as string;
> > }
> > catch { }
>

>> if (strMAPIEmailAddress.Contains("@"))
> > {
> > return strMAPIEmailAddress;
> > }
> > break;
> > }
>

>> case true: //Cached Mode
> > {
> > //Access MAPI property (proxy)
> > string[] strMAPIEmailAddressProxy = null;
>

>> try
> > {
> > strMAPIEmailAddressProxy =
> > objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
> > + PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];
> > foreach (string strItem in
> > strMAPIEmailAddressProxy)
> > {
> > if (strItem.Contains("SMTP:") &&
> > strItem.Contains("@"))
> > {
> > strItem.Replace("SMTP:", "");
> > strItem.Trim();
> > return strItem;
> > }
> > }
> > }
> > catch { }
> > break;
> > }
> > }
> > return null;
> > }
>

>
>> /// <summary
>> /// Returns True if in Exchange Cached Mode
> > /// </summary
>> /// <returns></returns
>> public bool fIsInExchangeCachedMode()
> > {
> > switch
> > (Globals.ThisAddIn.Application.Session.ExchangeConnectionMode)
> > {
> > case
> > Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle: { return
> > true;}
> > case
> > Outlook.OlExchangeConnectionMode.olCachedConnectedFull: { return true;}
> > case
> > Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders: { return
> > true;}
> > case
> > Outlook.OlExchangeConnectionMode.olCachedDisconnected: { return true;}
> > case Outlook.OlExchangeConnectionMode.olCachedOffline: {
> > return true;}
> > case Outlook.OlExchangeConnectionMode.olNoExchange: {
> > break; }
> > case Outlook.OlExchangeConnectionMode.olOffline: {
> > break; }
> > case Outlook.OlExchangeConnectionMode.olOnline:{ break; }
> > }
> > return false;
> > }
> > }
> > }
> >

>
 
That would be the pattern, yes.

"Mark B" <none123@none.com> wrote in message

news:e1vwjxLvKHA.5340@TK2MSFTNGP04.phx.gbl...
> Apologies. I was just showing it in case anyone saw something wrong with
> it since my testing here is a bit limited since I don't have Exchange.

> My assumption with this particular block of code here is that the format
> of the string elements in PR_EMS_AB_PROXY_ADDRESSES is:

> "SMTP:joe@company1.com"
> "smtp:fred@company2.com"

> since I extract the SMTP: bit. If that's not the case please let me know.

> case true: //Cached Mode
> {
> //Access MAPI property (proxy)
> string[] strMAPIEmailAddressProxy = null;

> try
> {
> strMAPIEmailAddressProxy =
> objRecipients[1].AddressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/"
> + PR_EMS_AB_PROXY_ADDRESSES.ToString()) as string[];
> foreach (string strItem in
> strMAPIEmailAddressProxy)
> {
> if (strItem.Contains("SMTP:") &&
> strItem.Contains("@"))
> {
> strItem.Replace("SMTP:", "");
> strItem.Trim();
> return strItem;
> }
> }
> }
> catch { }
> break;

>
 
I guess the answer is sitting next to this post. Buy a Redemption


component.It saves me a lot of time.






+1 same for me
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
J Signatures that contain recipient's email address Outlook VBA and Custom Forms 7
H How to show recipient email address? Using Outlook 0
J Searh For Recipient Email address Outlook VBA and Custom Forms 1
Diane Poremsky Display the Recipient Email Address in the Sent Items Folder Using Outlook 0
D Outlook VBA to open Excel attachment and send recipient's email address to a workbook cell? Using Outlook 4
J Recipient email address doesn't get underlined Using Outlook 4
T recipient email address is invalid, but resolved property is true Outlook VBA and Custom Forms 3
F Graphics in email / Mac recipient garbled Using Outlook 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
M ERROR: None of your email accounts could send to this recipient Using Outlook 2
E Send a Reminder/Task to certain Email Recipient Using Outlook 5
E Automatically pick up Recipient's Name on the Body of the Email Message Using Outlook 1
Aussie Looking for Outlook macro to Copy Recipient Names into Email Body Outlook VBA and Custom Forms 3
G Published Email Form Doesn't Display Text Boxes to the Recipient Using Outlook 0
R OL10 - Send To "Mail Recipient" doesn't go to default email account Using Outlook 23
M form or template associated to a specific email recipient Outlook VBA and Custom Forms 3
T Outlook 2010 recipient no longer shows in 'Send To' Using Outlook 0
S Adding a recipient's column to Sent folder in Outlook 2010 Outlook VBA and Custom Forms 1
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
C Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 4
T "Words In Recipient's Address" Rule Causes Outlook To Stop Processing Rules Using Outlook 3
N Custom Form Controls Not Visible To Recipient Outlook VBA and Custom Forms 3
Daniel Schunk User-defined form arrives empty at the recipient Using Outlook 3
D Moving Emails Based on Recipient/Sender Outlook VBA and Custom Forms 4
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
M recipient cache? Using Outlook 2
N Importing Google contacts from CSV file removes recipient names in autocomplete list Using Outlook 0
R OL2010 - Send to Mail Recipient going to wrong account Using Outlook 1
A Extracting only one recipient from Msgitem.To Outlook VBA and Custom Forms 7
E Meeting reminders are set for the recipient Exchange Server Administration 9
B Recipient of a forwared message getting multiple emails Using Outlook 2
L Outlook underlining all text after being sent to recipient Using Outlook 3
W Change Template Recipient Automatically - Outlook 2007 Using Outlook 5
L Contact Form - Recipient Control Field Using Outlook 2
F Seeing the recipient in sent emails Using Outlook 1
J 2010 appointment for recipient shows as mail Using Outlook 3
K TextBox on Custom Form Page :: Passing value from sender to the recipient Outlook VBA and Custom Forms 1
K Recipient's name replaced by open and closed brackets! Using Outlook 2
R POP3 Mail repeating while sending to group of recipient Using Outlook 1
J Outlook messagebox with name recipient Using Outlook 1
M Including a Public Calendar as a Meeting Recipient Using Outlook 3
N Reply from recipient Using Outlook 5
A 5.7.1 Recipient not authorized, your IP has been found on a block list Using Outlook 1
S Meeting Requests - ex-employee being invite, but not in recipient list Exchange Server Administration 3
M Changing Outlook Account Based on Recipient Using Outlook 15
S use the custom form to show meeting request in recipient's calendar Outlook VBA and Custom Forms 1

Similar threads

Back
Top