We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Russian Characters Are Displayed as "?" in EML Files

Hello,

I’m trying to save a .eml file using this code:

public void SaveToFile(string outputFilePath)
{
if (SaveOptions == null)
SaveOptions = GetSaveOptionsByExtension(); //returns new EmlSaveOptions(MailMessageSaveType.EmlFormat);

    _message.Body = "Здравствуйте";
    _message.Subject = "Здравствуйте";
    _message.Save(outputFilePath, SaveOptions);
}

In the generated file all russian characters are displayed as “???”. Can someone check please?
file.zip (578 Bytes)

@arnoldbeilandevozon,

Thank you for using Aspose.Email.

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);
        }
    }
}

message.zip (398 Bytes)

Maybe I was not clear enough. I will post the code again so you guys can reproduce the issue.

class Program
    {
        static void Main(string[] args)
        {
            var filePath = "path to testFile.eml";
            MailMessage message = MailMessage.Load(filePath);

            message.Subject = "Здравствуйте";
            message.Body = "\nЗдравствуйте\nЗдравствуйте\nЗдравствуйте";

            var emlSaveOptions = new EmlSaveOptions(Aspose.Email.MailMessageSaveType.EmlFormat);
            message.Save("finalResult.eml", emlSaveOptions);
        }
    }

files.zip (1012 Bytes)

@arnoldbeilandevozon,

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);
        }
    }
}

The code works good, thanks!

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,

Thank you for the question. I will reply to you as soon as possible.

@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.

The issues you have found earlier (filed as EMAILNET-40455) have been fixed in this update.