In a VSTO Add-In, I am trying to retrieve the email address of the user connected to Outlook. For security reason, I would like to ensure that the user was authenticated to the Exchange server prior using the email address. The authentication can be direct when inside the domain or from outside using Outlook Anywhere or similar authentication mechanisms. So far, I have the following code:
string authUserEmail = "";
string notAuthUserEmail = "";
AddressEntry currentUserAddressEntry = Application.Session.CurrentUser.AddressEntry;
if (currentUserAddressEntry.Type.Contains("Exchange"))
{
ExchangeUser currentExUser = currentUserAddressEntry.GetExchangeUser();
if(currentExUser != null)
authUserEmail = currentExUser.PrimarySmtpAddress;
}
if (authUserEmail == "")
{
string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
notAuthUserEmail = currentUserAddressEntry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
}
My questions are:
- Can I rely on the GetExchangeUser() function to retrieve the details of the Exchange authenticated user? I read the post here indicating that it could be an issue.
- Is there a better way to check if the user is authenticated against the exchange environment? Would the ExchangeConnectionMode property be a better way?
- If I rely on the PropertyAccessor property, how safe will this be to prevent someone from faking someone else email address?
References: