Thread
:
Get recipient's email address
View Single Post
#
7
March 5th 10, 01:56 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
Posts: 5,848
Get recipient's email address
Did you have a question, or are you showing your solution for the problem?
--
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
...
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
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.ExchangeCon nectionMode)
{
case
Outlook.OlExchangeConnectionMode.olCachedConnected Drizzle: { return true;}
case
Outlook.OlExchangeConnectionMode.olCachedConnected Full: { return true;}
case
Outlook.OlExchangeConnectionMode.olCachedConnected Headers: { return true;}
case Outlook.OlExchangeConnectionMode.olCachedDisconnec ted:
{ 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;
}
}
}
Ken Slovak - [MVP - Outlook]
View Public Profile
View message headers
Find all posts by Ken Slovak - [MVP - Outlook]
Find all threads started by Ken Slovak - [MVP - Outlook]
Ads