populating dataset with elements of outlook inbox

Discussion in 'ASP .Net' started by Mike P, Feb 19, 2007.

  1. Mike P

    Mike P Guest

    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;



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Mike P, Feb 19, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike P

    trying to access outlook inbox

    Mike P, Mar 13, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    344
    Mike P
    Mar 13, 2007
  2. Mike P

    Foreach item is Outlook inbox

    Mike P, May 29, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    383
    Mark Rae
    May 29, 2007
  3. Replies:
    4
    Views:
    297
  4. Replies:
    2
    Views:
    463
    Ben Morrow
    Aug 14, 2006
  5. Replies:
    0
    Views:
    155
Loading...

Share This Page