SMTP HTML email not rendering HTML via Gmail email client

Viewed 444

I am sending an email via C# SMTP. It's a HTML email which separates lines by
tags, e.g. :

Dear Test,

A password request has been initiated for your account. Please click this link....

This renders fine in an Outlook inbox, but in Gmail it seemingly ignores the
tags:

Gmail p

Outlook enter image description here

Why isn't Gmail rendering the HTML? It's the same result via the web browser as the Android email client.

When I view the source of the Gmail email and download the .eml file from Gmail the email contains the br tags.

I tried replacing the br tags with line breaks, but when I do that the opposite happens - it doesn't render the line breaks in Outlook but it does render them in Gmail.

What's actually going on here and how can I satisfy all email clients?

Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Here is my C# for generating the emails:

var mailMessage = new MailMessage
{
    Subject = subject,
    BodyEncoding = Encoding.UTF8,
    From = new MailAddress(EmailFrom),
    IsBodyHtml = true
};

var htmlView = AlternateView.CreateAlternateViewFromString(body.ReplaceLineBreaksWithHtmlLineBreak(), new ContentType("text/html"));
htmlView.ContentType.CharSet = Encoding.UTF8.WebName;
mailMessage.AlternateViews.Add(htmlView);

var plainView = AlternateView.CreateAlternateViewFromString(body.StripHtml(), new ContentType("text/plain"));
plainView.ContentType.CharSet = Encoding.UTF8.WebName;
mailMessage.AlternateViews.Add(plainView);

For the HTML email, I replace line breaks in my template string with br tags. For the plain text view, any HTML is stripped out.

UPDATE: It turns out on my plaintext view I was accidentally stripping out the line breaks. This solves the problem but another question I have is why does Gmail seemingly only render the plaintext version of the email?

0 Answers
Related