How to read Outlook EMail Using Asp.net

No.of Views2218
Bookmarked0 times
Downloads 
Votes0
By  dipal   On  15 Feb 2010 23:02:52
Tag : ASP.NET , How to
How to read Outlook EMail Using Asp.net
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article have detail about read outlook email with ASP.NET.

Complete Code

{codecitation class="brush: csharp; gutter: true;" width="650px"}

Private void ToReadMail()
{

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();



// Get Mapi NameSpace.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");


oNS.Logon("Outlook Profile Name", Missing.Value, false, true);
// TODO:

// Get Messages collection of Inbox.
Microsoft.Office.Interop.Outlook.MAPIFolder oInbox = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook.Items oItems = oInbox.Items;
Console.WriteLine("Total : " + oItems.Count);

//oInbox.Items.Sort("[Received]", "desc");



// Get unread e-mail messages.
oItems = oItems.Restrict("[Unread] = true");
Console.WriteLine("Total Unread : " + oItems.Count);

foreach (Microsoft.Office.Interop.Outlook.MailItem oMsg in oInbox.Items)
{

GC.Collect();
GC.WaitForPendingFinalizers();

if (oMsg.UnRead == true) // Here you can get your
{
//You also get Subject , body and Receivetime in oMsg object
// Do your action
}

}

oNS.Logoff();

// Clean up.
oApp = null;
oNS = null;
oItems = null;
}


{/codecitation}



Thank you

Dipal

 
Sign Up to vote for this article
 
About Author
 
dipal
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-10 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
By:NitinDate Of Posted:5/25/2010 6:13:21 PM
Notification..
Hi, Thank you for the article. I am trying to do something like this in WinForms. I would like to display notification when new mail is arrived. Any idea how to do it? Thank you Nitin
By:NitinDate Of Posted:5/25/2010 6:12:23 PM
Notification..
Hi, Thank you for the article. I am trying to do something like this in WinForms. I would like to display notification when new mail is arrived. Any idea how to do it? Thank you Nitin
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top