Reputation: 1478
I am trying to determine sender of a email in Outlook 2007 and above. In Outlook 2010 you have a Sender
property on the MailItem
object while in Outlook 2007 you have to do it differently like mentioned in this question.
So now I need to know whether current version of Outlook supports the Sender
property, and if it does not, use the other method. The reason for doing this is I would prefer to use the Sender
property for compatibility with future versions of Outlook rather than having condition on version of Outlook.
So the question is how do I determine whether a property exists in Outlook Interop ? Obviously, this being a COM object I cannot use reflection here.
Upvotes: 0
Views: 1723
Reputation: 1478
I used the MailItem.ItemProperties collection to check for the "Sender" property. Below is the code
Microsoft.Office.Interop.Outlook.MailItem myMail;
//Code to get the mail
....
Microsoft.Office.Interop.Outlook.ItemProperties mailProps = myMail.ItemProperties;
Microsoft.Office.Interop.Outlook.ItemProperty mailProp = mailProps.Item ("Sender"); //the parameter is case-sensitive
if(mailProp != null)
{
//get email address using Sender object
Microsoft.Office.Interop.Outlook.AddressEntry theSender = myMail.Sender;
}
else
{
//use alternate method for Outlook 2007
}
Upvotes: 1
Reputation: 24413
You can use IDispatch::GetIDsOfNames to see if the property exists
Upvotes: 0