Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an HTML email in a web application?

I wrote a web application that fetches email via IMAP. I now need to display these emails to the user. I thought it would be simple (I am displaying HTML within an HTML-capable browser) until I looked into this a little... and discovered that there are tons of issues, such as:

  • Javascript & security
  • Style breaking
  • Surely more

Is there a good, safe way to display an HTML email? I would err for "safe" rather than "gorgeous", even though I don't want to display just the text version of an email (which is not even guaranteed to be there anyway...)

I realise the most obvious answer is "put everything in a frame" -- is that really it though? Will it actually work?

I am using Node server side if it helps...

like image 537
Merc Avatar asked Oct 22 '14 03:10

Merc


People also ask

How do I send an email in HTML?

HTML Email Tag. HTML <a> tag provides you option to specify an email address to send an email. While using <a> tag as an email tag, you will use mailto: email address along with href attribute. Following is the syntax of using mailto instead of using http. <a href = "mailto: [email protected]">Send Email</a>

What is an HTML email table?

An HTML email is made up of multiple table elements. Each table element represents a different section of the email, including the header, body, and footer. Below is a very basic HTML email table template.

How to use <a> tag as an email address in HTML?

HTML <a> tag provides you option to specify an email address to send an email. While using <a> tag as an email tag, you will use mailto: email address along with href attribute.

How to make an HTML email responsive?

You can make an HTML email responsive by setting the container div to a fixed width and setting the width of the nested tables to 100%. Here’s a closer look at the syntax of the container div with only one table.


1 Answers

..most obvious answer is "put everything in a frame"...will it actually work?

Yes, e.g. Whiteout Networks GmbH's WHITEOUT.IO does it in /src/tpl/read.html and /src/js/controller/read-sandbox.js. Some of the security issues are handled by DOMPurify

..there are tons of issues..Is there a good, safe way..?

I know the message data format also under names EML or MHTML so looking for a good "XY to HTML converter" or "HTML5 document viewer with XY support" may point you to a usable results (e.g. GroupDocs.Viewer)

Some e-mail clients (e.g. GMail) don't use iframe, instead they use a mail parser (e.g. andris9/mailparser) and a HTML parser (e.g. cheeriojs/cheerio) to extract an e-mail-safe-html subset (see Stack Overflow: What guidelines for HTML email design are there? and Stack Overflow: Styling html email for GMail for some examples) or use a HTML sanitizer (e.g. Google's Caja, cure53/DOMPurify) and embed the code directly into the page.

But it is not always an easy thing, there is no consensus on what constitutes the e-mail-safe-html subset and you certainly don't wont to inline possibly infected attachments nor run anonymous CORS scripts within the secured user's session.

Anyway, as always, studying source code of various e-mail clients (see Wikipedia: Comparison of email clients) is the way to find out..

like image 174
xmojmr Avatar answered Oct 06 '22 21:10

xmojmr