Extracting attachement from .msg file

Bageshkumarbagi
Posted by Bageshkumarbagi under C# category on | Points: 40 | Views : 2360
before that you need to refer Microsoft.Office.Interop.Outlook.dll

using Microsoft.Office;
using Microsoft.Office.Interop.Outlook;

private void btnExtract_Click(object sender, EventArgs e)
{
// Create a new Application Class
_Application outlook;
outlook = new Microsoft.Office.Interop.Outlook.Application();
// Create a MailItem object
MailItem item = (MailItem)outlook.CreateItemFromTemplate(@"D:\pdf\OutLookTest.msg", Type.Missing);

for (int i = 1; i <item.Attachments.Count+1; i++)
{
string attpath = @"D:\" + item.Attachments[i].FileName;
item.Attachments[i].SaveAsFile(attpath);

}

}

Comments or Responses

Login to post response