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.
Asked
Active
Viewed 6,604 times
1

Community
- 1
- 1

Fox Vĩnh Tâm
- 150
- 1
- 2
- 15
-
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 06: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 06:28
2 Answers
4
In Interop Outlook, this is how to locally save a mail as .msg.
mailItem.SaveAs(@"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olMSG);

Gokul
- 788
- 2
- 12
- 30
2
How exactly are you creating the MSG file? It is completely different from an EML file - see https://stackoverflow.com/questions/16229591/difference-between-a-msg-file-and-a-eml-file/16230261#16230261
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 (I am its author), 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

Dmitry Streblechenko
- 62,942
- 4
- 53
- 78
-
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 06: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#)?](http://stackoverflow.com/questions/37451220/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#)?](http://stackoverflow.com/questions/37451220/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
-
So you are dealing with EML just to be able to set the Unicode characters? This doesn't make much sense to me.. – Dmitry Streblechenko May 26 '16 at 20:31
-
Sorry for the disrespectful, I'm just trying to find a solution for my issue. And I need to try it with difference ways. Apologize if this is to offend you and thank you for your interest. – Fox Vĩnh Tâm May 27 '16 at 01:32
-
No offence at all, I am just trying to understand what you are trying to do and why. – Dmitry Streblechenko May 27 '16 at 03:49