populating dataset with elements of outlook inbox

M

Mike P

I have a collection of objects (oItems) that I want to use to populate a
dataset. Basically I want to take several elements from oItems (such as
SenderName, Subject and Body) and use them to populate separate columns
of a dataset, and then use the dataset to populate a gridview.
Can anybody help me out with this?


//Create Outlook application
Outlook.Application oApp = new Outlook.Application();

//Get MAPI namespace
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

oNS.Logon("name", "password", false, true);

//Get Messages collection of Inbox
Outlook.MAPIFolder oInbox =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

Outlook.Items oItems = oInbox.Items;

int intTotalNumberOfItemsInInbox = oItems.Count;

//Get unread e-mail messages
oItems = oItems.Restrict("[Unread] = true");
int intTotalUnread = oItems.Count;


//Loop through each unread message
Outlook.MailItem oMsg;
int i;

for (i = 1; i < oItems.Count; i++)
{
oMsg = (Outlook.MailItem)oItems.Item(i);

txtSenderName.Text = oMsg.SenderName.ToString();
txtSubject.Text = oMsg.Subject.ToString();
txtReceivedTime.Text = oMsg.ReceivedTime.ToString();
txtBody.Text = oMsg.Body.ToString();
}

//Log off
oNS.Logoff();

//Clean up
oApp = null;
oNS = null;
oItems = null;
oMsg = null;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top