Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder myContacts = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
mapiNameSpace.Logon(null, null, false, false);
mapiNameSpace.Logon("YourOutlookMailID", "Password", Missing.Value, true);
Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
Microsoft.Office.Interop.Outlook.Items inboxItems = myInbox.Items;
Microsoft.Office.Interop.Outlook.Explorer myexp = myInbox.GetExplorer(false);
mapiNameSpace.Logon("Profile", Missing.Value, false, true);
if (myInbox.Items.Count > 0)
{
Console.WriteLine(string.Format("Total Unread message {0}:", inboxItems.Count));
int x=0;
foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
{
Console.WriteLine("{0} unread mail from your inbox", ++x);
Console.WriteLine(string.Format("from:- {0}", item.SenderName));
Console.WriteLine(string.Format("To:- {0}", item.ReceivedByName));
Console.WriteLine(string.Format("Subject:- {0}", item.Subject));
Console.WriteLine(string.Format("Message:- {0}", item.Body));
System.Threading.Thread.Sleep(1000);
}
Console.ReadKey();
}
<pre></pre>
happy coding :) :) :)