web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Email with weird characters

(0) ShareShare
ReportReport
Posted on by 241

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

I have the same question (0)
  • Holly Li Profile Picture
    241 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
    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
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans