mtlca401 mtlca401 - 4 months ago 23
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
does not work. The intellisense does not pull up anything when I type a period after
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?


The documentation for the Outlook MailItem object is here:

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.