How to read emails from .PST file from outlook using c#

 

We can read emails is from selected .PST file in asp .net c# and export it to excel or notepad file etc..

If you want to write all email from .PST file then you need to write code like…

you need to first add refrence to the page Microsoft.Office.Interop.Outlook;

 

Outlook.Application olApp = new Outlook.ApplicationClass();
olApp.Session.AddStore(“PST path here”);
Outlook.MAPIFolder folder¬† = OlApp.Getnamespace(“MAPI”).Folders.GetLast();
Outlook.Items items = folder.items;

foreach (Outlook.MailItem item in folder.items)
{
Console.WriteLine(item.SenderEmailAddress + ” ” + item.Subject + “\n” + item.Body);
}