Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Email with weird characters

Posted on by 235

We have crm 365 on-pre v9 that uses server sync connecting to exchange email server. I created a workflow that send out emails with HTML attachment. When the attachment is opened with chrome, the attachment shows html source and weird characters(square with question mark). Almost like it has wrong encoding.

The html is like:

readonly static string messageHead = @"<html>

<head>

<meta charset=""UTF-8"">

<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" />

<title>Invoice</title>

</head>

<body>

some text

</body>";

ActivityMimeAttachment attachment = new ActivityMimeAttachment();

attachment.MimeType = "text/html";

attachment.ObjectId = new EntityReference(Email.EntityLogicalName, mailId);

attachment.ObjectTypeCode = Email.EntityLogicalName;

attachment.FileName = String.Format("Invoice.{0}.html", v.Key);

attachment.AttachmentNumber = attachNo++;

attachment.Body = Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(v.Value.ToString()));

files.Add(attachment);

Am I doing something wrong? Thanks

Holly Li

*This post is locked for comments

  • Holly Li Profile Picture
    Holly Li 235 on at
    RE: Email with weird characters

    Thank you for the help. I change to attachment.Body = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(emailbodycontent);

    Then it works.

  • Suggested answer
    _Lars_ Profile Picture
    _Lars_ 225 on at
    RE: Email with weird characters

    Hello Holly!

    In this document I see you mix the encoding. You have set the HTML meta to UTF-8, content type top iso-8859-1 (Latin-1) and you set the body to Unicode (Unicode.GetBytes).

    What I would recommend to do is to look at the sources of your data. You need to know that if you want to output UTF-8 then you need to know the encoding of the data. If its UTF-8 then you dont need to do anything, but its anything else you need to use the helpers and GetBytes and convert them.

    You are getting weird symbols because the documents/data aren't the encoding you think it is.

  • Suggested answer
    JandostKhoso Profile Picture
    JandostKhoso 266 on at
    RE: Email with weird characters

    Hello

    Have you tried opening the email in other browsers? I typically see the behavior of Chrome is different than other browsers.

    I can think of two solutions:

    First, try to see if the issue is reproduceable in other browsers as well. Then:

    1. set the MIME type tp "text/html; charset="UTF-8"

    2. Try using unicode character representation in your html.

    Explanation:

    My understanding is "Email clients display emails based on the content-type of the Email and not their attached html file. Email clients read the content-type value set in the email header and they ignore the meta tag within the HTML."

    Nearly every email client renders text based on the content-type value set in the email header. Gmail is the only client that automatically converts your text to UTF-8, regardless of what you set in the header.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans