Email attachment become unclear after reading it with UTF-8 (C#)

When I use the email content as the attachment, and read it using UTF-8 encoding, and finally
I received a garbled message.

My Code : MyCode.zip (525 Bytes)

email content : Notification-1.zip (50.2 KB)

I correct the description above that when the mail content using the chinese word, the chinese word is garbled.

please use this email content instead of the one above : Notification-1-chinese-word.zip (50.6 KB)

I found the strange charset=“Windows-1252” in the mail header.
PS. my aspose.email component is version 18.3

The mail header detail below :

    Received: from [mail.dajinsoft.com](http://mail.dajinsoft.com/) (172.16.1.103) by [mail.dajinsoft.com](http://mail.dajinsoft.com/)
    (172.16.1.103) with Microsoft SMTP Server (version=TLS1_2,
    cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.845.34 via Mailbox
    Transport; Fri, 24 May 2019 16:54:32 +0800
    Received: from [mail.dajinsoft.com](http://mail.dajinsoft.com/) (172.16.1.103) by [mail.dajinsoft.com](http://mail.dajinsoft.com/)
    (172.16.1.103) with Microsoft SMTP Server (version=TLS1_2,
    cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.845.34; Fri, 24 May
    2019 16:54:32 +0800
    Received: from DESKTOP-IBUFQEV (172.16.1.161) by [mail.dajinsoft.com](http://mail.dajinsoft.com/)
    (172.16.1.103) with Microsoft SMTP Server id 15.1.845.34 via Frontend
    Transport; Fri, 24 May 2019 16:54:32 +0800
    X-Unsent: 1
    Message-ID: <60faa0114f4b49eb9c82f12d8f73f5fc>
    Sender: =?utf-8?B?6YGU55Kf6LOH6KiKIERhamluc29mdA==?= [support@dajinsoft.com](mailto:support@dajinsoft.com)
    From: =?utf-8?B?6YGU55Kf6LOH6KiK?= [crm@dajinsoft.com](mailto:crm@dajinsoft.com)
    Subject: =?utf-8?B?5rS75YuV5aCx5ZCN6YCa55+l?=
    To: [carlos_liu@dajinsoft.com](mailto:carlos_liu@dajinsoft.com)
    Date: Fri, 24 May 2019 08:54:29 +0000
    Content-Type: text/html; charset=“Windows-1252”
    Content-Transfer-Encoding: quoted-printable
    Return-Path: [support@dajinsoft.com](mailto:support@dajinsoft.com)
    X-MS-Exchange-Organization-Network-Message-Id: c2ffebe3-63c5-4c03-985e-08d6e0257042
    X-MS-Exchange-Organization-AVStamp-Enterprise: 1.0
    X-MS-Exchange-Organization-AuthSource: [mail.dajinsoft.com](http://mail.dajinsoft.com/)
    X-MS-Exchange-Organization-AuthAs: Anonymous
    X-MS-Exchange-Transport-EndToEndLatency: 00:00:00.1745110
    MIME-Version: 1.0

@carlos_liu,

I have observed the issue and information shared by you. I have tried using your sample code but it is using some custom objects like dto and custom method for getting SMTP connection. I suggest you to please first try using latest Aspose.Email 19.4 on your end. If there is still an issue then please provide a working sample project reproducing the issue along with generated output and desired output that you are expecting. Please share the requested information so that I may proceed to help you further.

I send a mail which content is contains traditional chinese word, and It should display like this image A01.png (10.8 KB)

but I got this image with chinese word is garbled B01.png (10.0 KB)

My code use an email template : EventReplyNotifyTemplate.zip (2.0 KB)

I use the code below :

        Aspose.Email.License license = new Aspose.Email.License();
        if (!license.IsLicensed)
        {
            //放在內嵌資源
            license.SetLicense("Aspose.Email.lic");
        }

        MailMessage MailMessage = new MailMessage();

        #region Sender (作為主要退信address)
        MailMessage.Sender = "support@dajinsoft.com";
        MailMessage.Sender.DisplayName = "達璟資訊 Dajinsoft";
        #endregion

        #region From
        MailMessage.From = "crm@dajinsoft.com";
        MailMessage.From.DisplayName = "達璟資訊";
        #endregion

        #region To
        MailMessage.To.Add("carlos_liu@dajinsoft.com");
        #endregion

        #region Content
        MailMessage.Subject = "諮詢回覆通知";
        StringBuilder sb = new StringBuilder();
        StreamReader sr = new StreamReader(@"C:\EventReplyNotifyTemplate.html", Encoding.UTF8);
        sb.Append(sr.ReadToEnd());            
        MailMessage.HtmlBody = sb.ToString();
        //MailMessage.IsBodyHtml = true;
        #endregion            

        MailMessage.BodyEncoding = Encoding.UTF8;
        MailMessage.SubjectEncoding = Encoding.UTF8;
        MailMessage.PreferredTextEncoding = Encoding.UTF8;
        

        SmtpClient client = new SmtpClient();
        client.Host = "exmail.dajinsoft.com";
        client.Username = "username";
        client.Password = "password";
        client.Port = 25;
        //client.UseAuthentication = false;
        //client.SupportedEncryption = Aspose.Email.Clients.Base.EncryptionProtocols.Ssl2;
        client.SecurityOptions = SecurityOptions.None;            
        client.Send(MailMessage);

@carlos_liu,

I like to inform that code snippet you have shared includes some undeclared variables so would you please share your SSCCE code reproducing the issue so that we may try to reproduce and investigate it in our environment.

This code is no more variable that I had modified the most short code sample. You can download sample code here http://www.dajinsoft.com/download/MyTestAPP.zip

@carlos_liu,

I have investigated this issue on my end and an issue with ID EMAILNET-39486 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hi, Do you find any solution for this issue ? The multiple language is normally usage.

@carlos_liu,

I like to inform that this issue is going to resolved tentatively in Aspose.Email 19.6. I request for your patience until issue get resolved.

I got it

Thanks

Hi, Is the issue fixed ?

@carlos_liu,

I like to inform that this issue has been resolved in Aspose.Email 19.6. Can you please check and share your feedback with us if there is still an issue.

I use Aspose.Email 19.7 to test, but the email I received is still garbled in chinese word 002.png (43.7 KB)
received msg receiced002.zip (7.6 KB)

My Code:
PS. the file C:\EventReplyNotifyTemplate.html is here EventReplyNotifyTemplate.zip (2.0 KB)

private void button2_Click(object sender, EventArgs e)
{
Aspose.Email.License license = new Aspose.Email.License();
//放在內嵌資源
license.SetLicense(“Aspose.Email.lic”);

        MailMessage MailMessage = new MailMessage();

        #region Sender (作為主要退信address)
        MailMessage.Sender = "support@dajinsoft.com";
        MailMessage.Sender.DisplayName = "達璟資訊 Dajinsoft";
        #endregion

        #region From
        MailMessage.From = "crm@dajinsoft.com";
        MailMessage.From.DisplayName = "達璟資訊";
        #endregion

        #region To
        MailMessage.To.Add("carlos_liu@dajinsoft.com");
        #endregion

        #region Content
        MailMessage.Subject = "諮詢回覆通知";
        StringBuilder sb = new StringBuilder();
        StreamReader sr = new StreamReader(@"C:\EventReplyNotifyTemplate.html", Encoding.UTF8);
        sb.Append(sr.ReadToEnd());            
        MailMessage.HtmlBody = sb.ToString();
        //MailMessage.IsBodyHtml = true;
        #endregion            

        MailMessage.BodyEncoding = Encoding.UTF8;
        MailMessage.SubjectEncoding = Encoding.UTF8;
        MailMessage.PreferredTextEncoding = Encoding.UTF8;
        

        SmtpClient client = new SmtpClient();
        client.Host = "exmail.dajinsoft.com";
        client.Username = "username";
        client.Password = "password";
        client.Port = 25;
        //client.UseAuthentication = false;
        //client.SupportedEncryption = Aspose.Email.Clients.Base.EncryptionProtocols.Ssl2;
        client.SecurityOptions = SecurityOptions.None;            
        client.Send(MailMessage);
        
    }

@carlos_liu,

I have observed your comments and like to inform that the BodyEncoding must be set before of body’s value, for example in a such way

StreamReader sr = new StreamReader(@“EventReplyNotifyTemplate.html”, Encoding.UTF8);
sb.Append(sr.ReadToEnd());
MailMessage.BodyEncoding = Encoding.UTF8;
MailMessage.HtmlBody = sb.ToString();

Thanks a lot, You solved my big problem !

@carlos_liu,

You are very welcome.