HTML email (from SendGrid) not being rendered properly - html

What Content-Type does SendGrid set in the header by default?
I have an issue where html email going thru Sendgrid is not being formatted properly.
In the email header I see
MIME-Version: 1.0
Content-Type: text/plain
and then the following is rendered in any email client, standalone or web based.
This is a multi-part message in MIME format.
--------------e21a5bffb444e61b8e8a30240210d506
Content-Type: text/html; charset=UTF-8; format=flowed
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
etc etc
Shouldn't the Content-type in the header be multipart/mixed or similar to properly render the html and display images?
How is this changed?
Can it be changed somehow by the actual html being sent to SendGrid's server?
Any feedback appreciated!

The library you are using is hardcoding the content-type to be text/plain. In the smtp/mailer/SMTPMailer.as source on line 135:
writeUTFBytes ("Content-Type: text/html; charset=UTF-8; format=flowed\r\n");
This library doesn't look like it's extremely robust, it's lacking documentation, and it's 6 years old. You may want to try to find a different solution.

Related

Why does Google use conflicting character encoding on it's homepage?

I've been doing some research on declaring character encodings, and thought I'd look at what google do on their homepage.
On the google homepage <head> tags they have:
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
But then in the http headers it's:
Content-Type: text/html; charset=ISO-8859-1
I'm interested in understanding they would do this.
Edit: It happens on https://google.com/ I'm certain I spotted this in the browser earlier, but now I get the expected content-type: text/html; charset=UTF-8. However, when I send a request from postman I get the same http header as before.
It appears that the response is based on the user-agent request header. If I send a request with a missing or unusual user-agent the response header is ISO-8859-1. Still not sure why this is done and would be interested in an explanation.

Where do I put an ETag, and what is the format?

I currently put this <meta cache-control: public ETag: "v019" />
in the <head> just under the <title>, but keep getting Errors in the W3 validator.
What is the format and where do I put this in my HTML5 file?
An ETag isn't useful unless it is in a real HTTP header. It shouldn't be in your HTML document at all.
That said, the syntax for an HTML meta tag with a simulation of an HTTP header is:
<meta http-equiv="cache-control" value="public">
<meta http-equiv="ETag" value=""v019"">
cache-control and ETag are not accepted values for it in HTML 5. You would need to be using HTML 4 or earlier (although it would still be pointless).

Microsoft Edge does not recognize content-type html

The following html is not recognised by MS Edge(Windows 10) and it downloads html as a file instead of rendering. It renders as html in Chrome and FireFox without any issues. The error is repeatable on other machines and IE 10
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
The problem is not with the file content, but with HTTP headers. You have to make sure that server sends proper Content-Type header, for example:
Content-Type: text/html; charset=iso-8859-1
Aaargh, I found the problem: The html that was downloading came from a .php file which included a PHP directive:
header('Content-Type: charset=ISO-8859-1');
This was overriding the content-type setting in default header html which was then downloaded as text as displayed in my original question above. This then made me think it was a MS Edge issue when in reality FireFox and Chrome must assume HTML as default content-type but Edge clearly does not. Anyhow, this change in php directive fixed the issue:
header('Content-Type: text/html; charset=ISO-8859-1');

Why max-age is ignored?

I have a simple html page which starts like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="public, must-revalidate">
<meta http-equiv="Cache-Control" content="max-age=88000" />
<script type="text/javascript" src="/js/index.js"></script>
....
However, when I check index.js file in FF web console, I see Cache-Control: "max-age=0". Why is that and how can I fix it? Thanks!
There is no reason to expect a meta tag in an HTML file to affect the HTTP headers sent for a JavaScript file that it refers to (or even the HTTP headers sent for the HTML file itself, for that matter).
The HTTP headers are set by the web server (or, more generally, HTTP server) software in use, possibly as affected by system-wide or directory-wide settings on the server. Long ago, the idea was that certain meta tags might affect the HTTP headers for the HTML document itself, but this was generally not implemented in servers. Instead, browsers may use some meta tags and act as if corresponding HTTP headers had been sent, but a) this only applies to the HTML document itself, if at all and b) it cannot be seen by tools that inspect the HTTP headers actually sent.

Html encoding defaults to "Western (ISO-8859-1)" locally

Lets say I have the following file in called index in the directory D:\Experimental:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<title>Minimal XHTML 1.1 Document</title>
</head>
<body>
<p>This is a minimal XHTML 1.1 document.</p>
</body>
</html>
If I open the link
file:///D:/experimental/index.html
I get to see the html, but it seems that the character encoding defaults to Western (ISO-8859-1), I can see this when I click view -> character encoding in firefox.
I want to display this in UTF-8 because Western (ISO-8859-1) doesn't display some characters correctly. Does anyone know how to fix this?
You should include:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
in your HEAD element.
Edit
I've just tried your example in Firefox on the Mac, and even without the meta tag, it correctly interprets the document as UTF-8. The Standard seems to indicate that it should use the XML processing instruction, but that you should also use the correct HTTP headers. Since you're not sending headers (because you're not using HTTP) you can specify them with the meta tag.
Maybe try adding
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
in <head> section?
When loading files from disk, your browser does not have an HTTP Content-Type header to read the encoding from, so it guesses. To guess the document encoding it uses your operative systems current encoding, the actual bytes that are in the files and information inside the file itself.
As Jonathan wrote, you can add a
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
element that will help the browser using the correct content type. Anyway, note that that element will often be ignored by browsers if your document is sent from a misconfigured HTTP server that explicitly specifies another encoding the Content-Type header.