Save Current Mail Item

Aug 10, 2015 at 10:30 AM
Edited Aug 10, 2015 at 10:49 AM
Hello,
     Its my first time creating an addin for outlook. I want to save the current mail item to the downloads folder but my code doesnt seem to work(it saves a type "file", i need .msg). Can anyone have a look at this?
        public void SendButton_Click(Office.IRibbonControl control)
        {
            try
            {
                var inspector= GlobalModule.ActiveInspector();
                var mail = test.CurrentItem as MailItem;
                string userRoot = System.Environment.GetEnvironmentVariable("USERPROFILE");
                string downloadFolder = Path.Combine(userRoot, "Downloads");
                mail.SaveAs(downloadFolder + @"\test", OlSaveAsType.olMSG);
                MessageBox.Show(downloadFolder, " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception e)
            {
                MessageBox.Show(string.Format("Error in Addins: {0}", e.ToString()), " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Thank you in advance :)
Developer
Sep 29, 2015 at 10:41 AM
You should add extension ".msg" to let Windows know that it is message file.
...
mail.SaveAs(downloadFolder + @"\test.msg", OlSaveAsType.olMSG);
...