mtlca401 mtlca401 - 2 months ago 18
C# Question

Get properties of outlook emails

My c sharp program currently gets outlook emails and imports them into a dataset. However, I am only getting the subject of each email.

I am using

Microsoft.Office.Interop.Outlook.Folder olCurrFolder;
which I use this variable to get the subject (olCurrFolder gets set from another loop). In order to get the subject I do this:

intMailCount = olCurrFolder.Items.Count;

for (int i = 1; i <= intMailCount; i++)
{
strSubject = olCurrFolder.Items[i].Subject;
strEmailReceived = olCurrFolder.Items[i].Received;
}


As you can see, I am also trying to get the received date, but
Items[i].Received
does not work. The intellisense does not pull up anything when I type a period after
Items[i]
and a message says it will be resolved at runtime. I have no idea what the other fields are called (i.e. Received Date, From, Size).

Is there a list that has the field names I am looking for?

Answer

The documentation for the Outlook MailItem object is here: http://msdn.microsoft.com/en-us/library/aa210946(v=office.11).aspx

You can use the ReceivedTime property to get the received date and time.

The reason that intellisense sometimes doesn't work with VSTO is that many of the properties return a dynamic. A dynamic is treated like an object that supports every method and property imaginable. This is what prevents intellisense from working. If you use a nonexistent method, it will compile, but fail at runtime.

I find the MSDN documentation is invaluable when working with dynamics in VSTO.