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
Thank you for the help. I change to attachment.Body = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(emailbodycontent);
Then it works.
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.
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156