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 (e-mail address removed) 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;
}
}
}