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

Free Support Forum - aspose.com

Unable to display Korean properly when loading EML files by Aspose.Email for .Net 20.4.0.0

Hi all,

I used EMLoadOptions by referring to the site below, but it has not been resolved.
https://github.com/aspose-email/Aspose.Email-for-.NET/blob/master/Examples/CSharp/Email/LoadMessageWithLoadOptions.cs

Two types of codes I use :
PrefferedTextEncoding = Encoding.GetEncoding(“euc-kr”)
PrefferedTextEncoding = Encoding.GetEncoding(“ks_c_5601-1987”)

Sample eml did not specify charset. (Attached file)
SAMPLE.zip (668 Bytes)

Thanks & Regards

@youngjoo.kim,

I have observed the issue shared. However, I am unable to observe any attached sample file. Can you please provide the sample file along with code sample that have used and snapshot of the issue.

@mudassir.fayyaz

I attached SAMPLE.zip above thread.

When I saw eml file by outlook :
image.png (76.1 KB)

snapshot of issues:
image.png (67.3 KB)

Used code is below :

class Program
{
static void Main(string[] args)
{
Aspose.Email.License license = new Aspose.Email.License();
license.SetLicense(“Properties\Aspose.Email.lic”);

        Aspose.Email.MailMessage message = Aspose.Email.MailMessage.Load(
            "SAMPLE.eml",
            new Aspose.Email.EmlLoadOptions() {
            });

        Console.WriteLine(message.BodyEncoding.BodyName);
        Console.WriteLine(message.Body);
    }
}

I need to load correctly even when there is no charset in the eml files.

@youngjoo.kim,

I have worked with sample code shared using latest Aspose.Email for .NET 20.5. There is no issue in API as when you check the message body in watch during debugging, the characters are extracted properly. You need to set the console encoding before printing the body string in console.

    public static void TestKoreanMsg()
    {
        String path = @"C:\Users\mudas\Downloads\SAMPLE(1)\";
        Aspose.Email.MailMessage message = Aspose.Email.MailMessage.Load(path+"SAMPLE.eml",new Aspose.Email.EmlLoadOptions()
        {
        });

        //Setting encoding of Console
        Console.OutputEncoding = System.Text.Encoding.UTF8;

        Console.WriteLine(message.BodyEncoding.BodyName);
        Console.WriteLine(message.Body);

    }

@mudassir.fayyaz
I have used visual studio 2017 and tested it with the latest Aspose.Email for .NET 20.5.
I still have same errors.

This is incorrect result :

iso-8859-1

-----Original Message-----
From: [sample@test.com](mailto:sample@test.com) [sample@test.com](mailto:sample@test.com)
Sent: Wednesday, April 29, 2020 6:07 PM
To: ¹®ÀÚÆÀ[Char Management Team] [char@test.com](mailto:char@test.com); ***Á¤±¤Á¶/***K J JEONG [kj.jeong@test.com](mailto:kj.jeong@test.com); [test@test.com](mailto:test@test.com)
Subject: ¹®ÀÚ-Ùýí®-Character

¹®ÀÚ-Ùýí®-Character

I uploaded the project I used by compressing it including the eml file and except lic file.
Please check if there is any problem in your environment with this project.
Test03.zip (5.8 KB)

This is correct result :

-----Original Message-----
From: [sample@test.com](mailto:sample@test.com) [sample@test.com](mailto:sample@test.com)
Sent: Wednesday, April 29, 2020 6:07 PM
To: 문자팀[Char Management Team] [char@test.com](mailto:char@test.com); 정광조/K J JEONG [kj.jeong@test.com](mailto:kj.jeong@test.com); [test@test.com](mailto:test@test.com)
Subject: 문자-問字-Character

문자-問字-Character

@youngjoo.kim,

Actually, your sample file is incorrect and there is issue of missing charset in your EML file. Therefore, MS Outlook, Notepad and Aspose.Email (other email clients too) can’t define encoding themselves and displays incorrect text.

Your problem can be fixed by 2 ways:

1: You need to provide correct character-set encoding while creating of your email. In the attached modified EML, we have added the character-set.
SAMPLE.zip (687 Bytes)

2: You can use PrefferedTextEncoding = Encoding.GetEncoding(949) when loading this email in Aspose.Email, then if you want output to console you should set Korean fonts on his machine and set Console.OutputEncoding = Encoding.GetEncoding(949); In Aspose.Email in order to handle such cases we have a field PrefferedTextEncoding in LoadOptions.

Aspose.Email.MailMessage message = Aspose.Email.MailMessage.Load(path+"SAMPLE.eml",new Aspose.Email.EmlLoadOptions()
{
  PrefferedTextEncoding = Encoding.GetEncoding(949)
});

Console.OutputEncoding = Encoding.GetEncoding(949);
Console.WriteLine(message.BodyEncoding.BodyName);
Console.WriteLine(message.Body);

NOTE: Exception may be thrown if you machine does not contains Korean fonts!.

Please check the following image. I have opened the EML file shared by you as it is in Notepad and MS Outlook. The output is identical to the one that is read by Aspose.Email on my end. You can observe that even Notepad and MS Outlook are exhibiting same behavior as that of Aspose.Email.