Save MailMessage as MSG format

I am getting this massage when I use the code:
Aspose.Email.MailMessage msg = new Aspose.Email.MailMessage();
msg.From = new Aspose.Email.MailAddress(“greg@gmail.com”);
msg.To = new Aspose.Email.MailAddress(“support@gmail.com”);
if (wsEmail.Cells[i, 16].StringValue != string.Empty)
msg.CC = new Aspose.Email.MailAddress(“cc@gmail.com”);
if (wsEmail.Cells[i, 16].StringValue != string.Empty)
msg.Bcc = new Aspose.Email.MailAddress(“bcc@gmail.com”);
msg.Body = “Some Text”;
msg.SetHtmlBody(“

Test Body

”, true);
msg.Subject = wsEmail.Cells[i, 11].StringValue;
msg.Date = DateTimeValue.Now;
msg.Save(@“c:\temp\1.msg”, Aspose.Email.SaveOptions.DefaultMsg);

System.NotSupportedException: ‘No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.’

I get the same error when convert to a MapiMessage and try and save also.
I have tried the latest download for Aspose.Email
What is causing this issue?

Hello @ggnuttall,

The error message suggests that the code is trying to use an encoding that is not supported or is not available in your environment.
To resolve this issue, you can try specifying a different character encoding or ensure that the required encoding is available in your system.

  1. You can try specifying a different encoding when saving the message. For example, you can use Unicode as follows:

    msg.Save(@"1.msg", Aspose.Email.SaveOptions.DefaultMsgUnicode);
    
  2. “No data is available for encoding 1252,” is related to character encoding. Encoding 1252 refers to Windows-1252 encoding.
    .NET Core can be extended to support Windows-1252 by registering the CodePagesEncodingProvider from the System.Text.Encoding.CodePages NuGet package.

    You can try the following:

    • First, add the System.Text.Encoding.CodePages reference to your project.
    • Secondly, get a CodePagesEncodingProvider object from the static Instance property and pass it to the Encoding.RegisterProvider method. For example: Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

Thanks for the reply.
Currently the project runs and the SetHTMLBody works find but on the Save function throws the error.
When I use Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); at the start of the project then the error is thrown on the SetHTMLBody command instead. I am passing a HTMLBody sourced from an existing email that I am reconstructing.
The actual HTML I am passing to the HTMLBody is attached in the text file.HTML.7z (4.5 KB)

Hello @ggnuttall ,

We cannot reproduce the error. Can you create a simple project in Visual Studio that reproduces your problem? Then share this project with us.

Thanks.

Thank you. I have gone back to a 2019 version of Visual Studio and do not have the issue now.
I think that maybe the project had the incorrect .Net version set for the project.

Hello,

Thanks for the feedback, we’re glad it worked out for you.