0

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.

Community
  • 1
  • 1
devanalyst
  • 1,348
  • 4
  • 28
  • 55
  • you've tried the try..catch-approach? That's often needed in COM interop. – Scoregraphic Aug 03 '12 at 06:49
  • @Scoregraphic, I had already tried that approach but it does not work. Outlook simply exits silently from in-between without going to the catch block. – devanalyst Aug 03 '12 at 07:39

2 Answers2

1

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 
}
devanalyst
  • 1,348
  • 4
  • 28
  • 55
0

You can use IDispatch::GetIDsOfNames to see if the property exists

parapura rajkumar
  • 24,045
  • 1
  • 55
  • 85
  • could you please elaborate a bit? I don't know how I should use this (and it doesn't seem like any registered user so far did) – Breeze May 06 '16 at 06:01