how to save mail form outlook with attachments?

13,482

What are you using as a filename? does it end with .msg?

I do something like this and it works as you describe you want it too:

Outlook.MailItem msg;
foreach (object obj in f.Mapi.Items)
{
    try
    {                        
         msg = obj as Outlook.MailItem;
         // ... set file name using message attributes
         // string fullPath = "something" + ".msg"
         msg.SaveAs(fullPath, Outlook.OlSaveAsType.olMSG);
     }
 }

The reason I'm so curious in your case is that I am wondering how I can reproduce what you are doing: saving the mail item with out saving the attachments?

Share:
13,482
user14761301
Author by

user14761301

Software Engineer with focus on Azure.

Updated on September 04, 2022

Comments

  • user14761301
    user14761301 over 1 year

    I wanted to save Outlook mails in to msg format along with the attachment through C#.

    I tried the following code

    using Outlook = Microsoft.Office.Interop.Outlook;
    
    private void button1_Click(object sender, EventArgs e)
    {  
    
    Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
    Outlook.NameSpace ns = app.GetNamespace("MAPI");
    Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    
    foreach (Outlook.MailItem item in inbox.Items)
    {
      item.SaveAs(finename, Outlook.OlSaveAsType.olMSG);
    }
    
    }
    

    It could save the mail as msg but the attachment part was removed. SaveAs method had no other overloads alos... :(

    If i try to save a message from outlook it saves the message along with the attachment embedded in it. Any idea how this can be achieved..?

    I am using .Net Framework 3.5 and Outolook 2007