I need save a MailMessage to .msg file. In this article have a solution but when I save as .msg file, it does not work in MS Outlook. It only great work when I save as.eml file.
How to save MailMessage object to disk as *.eml or *.msg file
Note that I get when open the .msg file:
Cannot open file: path. The file may not exist, you may not have permission to open it, or it may open in another program. Right-click the folder that contains the file, and then click Properties check your permisstions for the folder.
Thank all.
-
Where did you save the file? Is it the C: drive? Did you have a chance to check out permissions as was described in the error message? – Eugene Astafiev May 26 '16 at 6:12
-
@EugeneAstafiev I save to D:, but that is no problem. I can use and send those files created by my app. I just have a problem with show Vietnamese characters in subject mail. Thank you. – Fox Vĩnh Tâm May 26 '16 at 6:28
Add a comment
|
How exactly are you creating the MSG file? It is completely different from an EML file - see Difference between a .msg file and a .eml file
MSG file format is a binary IStorage file, and its format is documented. You can parse your EML (MIME) file and copy one property at a time to a programmatically created MSG file.
If using Redemption is an option, you can use Session.CreateMessageFromMsgFile to create a new MSG file and RDOMail.Import method to import your existing EML file.
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.CreateMessageFromMsgFile("c:\temp\test.msg")
Msg.Sent = true '//since Import does not copy this property
Msg.Import("c:\temp\test.eml", 1024) ' //1024 is olRfc822
Msg.Save
-
I don't use Redemption and I don't want to use 3rd-party tools. If you have another solution, please help me. Thank you. – Fox Vĩnh Tâm May 26 '16 at 6:32
-
If you don't want to use any third party products, you will need to handle MSG file creation and MIME file parsing explicitly in your code. Which can be challenging. – Dmitry Streblechenko May 26 '16 at 13:57
-
It means impossible without using 3rd party software? I hope you will see my article and if I looking forward to receiving your help. Thank you for your interest. How to show Vietnamese characters in subjects mail .msg file Outlook (saved by C#)? – Fox Vĩnh Tâm May 26 '16 at 14:36
-
So what exactly are you trying to do? Convert an EML file to MSG? – Dmitry Streblechenko May 26 '16 at 15:32
-
Convert an EML file to MSG, that can a solution. I want to use MailMessage because it can Encoding Subject. I need to show Vietnamese characters in subject as mentioned in article How to show Vietnamese characters in subjects mail .msg file Outlook (saved by C#)? – Fox Vĩnh Tâm May 26 '16 at 16:09
In Interop Outlook, this is how to locally save a mail as .msg.
mailItem.SaveAs(@"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olMSG);