public void SaveToFile(string outputFilePath)
{
if (SaveOptions == null)
SaveOptions = GetSaveOptionsByExtension(); //returns new EmlSaveOptions(MailMessageSaveType.EmlFormat);
The file you attached doesn’t contain the body and title you used in the example you have shared. Could you please attach the file generated with the code example? What application do you use to view the generated file?
Please view the example below. I used Aspose.Email for .NET 21.9. I have attached the file generated with the example.
using System;
using Aspose.Email;
namespace AsposeEmailTests
{
class Program
{
static void Main(string[] args)
{
var license = new License();
license.SetLicense("Aspose.Email.NET.lic");
var message = new MailMessage("from@domain.com", "to@domain.com");
message.Subject = "Здравствуйте";
message.Body = "Здравствуйте";
var emlSaveOptions = new EmlSaveOptions(Aspose.Email.MailMessageSaveType.EmlFormat);
message.Save("message.eml", emlSaveOptions);
}
}
}
Thank you for the more detailed example. I have reproduced the issue.
The source EML file doesn’t contain information about encoding. So the default Windows-1252 (Latin) encoding is used for saving the message. This encoding doesn’t have Cyrillic symbols.
You can specify EmlLoadOptions.PrefferedTextEncoding for message loading. Or you can specify MailMessage.SubjectEncoding and MailMessage.BodyEncoding. In both cases, the message will be saved correctly.
using Aspose.Email;
namespace AsposeEmailTests
{
class Program
{
static void Main(string[] args)
{
var license = new License();
license.SetLicense("Aspose.Total.NET.lic");
var filePath = "testFile.eml";
var emlLoadOptions = new EmlLoadOptions();
// way 1 >>>
emlLoadOptions.PrefferedTextEncoding = System.Text.Encoding.UTF8;
// <<<
MailMessage message = MailMessage.Load(filePath, emlLoadOptions);
// way 2 >>>
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// <<<
message.Subject = "Здравствуйте";
message.Body = "\nЗдравствуйте\nЗдравствуйте\nЗдравствуйте";
var emlSaveOptions = new EmlSaveOptions(Aspose.Email.MailMessageSaveType.EmlFormat);
message.Save("finalResult.eml", emlSaveOptions);
}
}
}
Just to confim. If I load an EML file that contains information about encoding, will it keep the file encoding or it will take the value from PrefferedTextEncoding ?
@arnoldbeilandevozon,
I have found out the EmlLoadOptions.PrefferedTextEncoding option should change encodings of MailMessage objects. But it seems to be it does not work for your “finalResult.eml” file. I logged the issue with ID EMAILNET-40455 in our tracking system. Our development team will investigate this case. We will inform you of any progress.