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 |