Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening and viewing Eml files in Html

Tags:

javascript

eml

I am trying to create a JS script to open and view Eml file. But till now I am stuck and with no way to go further. Can someone give me some directions. I was planning to post back my findings here with code so others can benefit too.

like image 743
esafwan Avatar asked Oct 12 '14 14:10

esafwan


People also ask

Can you convert EML to HTML?

How to convert a EML to a HTML file? Choose the EML file that you want to convert. Select HTML as the the format you want to convert your EML file to. Click "Convert" to convert your EML file.

How do I view an EML file?

Open Windows File Explorer and locate the EML file you want to open. Right-click the EML file and select Open With. Select Mail or Windows Mail. The file opens in the Windows email program.

How do I open an EML file in browser?

Right-click on an EML file ans select Open with >. Click on Select another app. Pick the specific browser; you may have to search for it if it is not in the list. Check Always use this app to open .

How do I open a .EML file in Chrome?

You can even open EML files inside Google Chrome by dragging the file from your desktop onto a new browser table. EML files contains the email content (email body, header and encoded images and attachments) as plain text in MIME format.


Video Answer


1 Answers

The first step is to load the EML file either as a String or as a Stream. A EML file should look like this:

Date: Wed, 29 Jan 2014 11:10:06 +0100
To: "Foo Bar" <[email protected]>
From: Online Shop <[email protected]>
Subject: Winter promotions
Content-Type: text/plain; charset=utf-8

Some Content

If you are looking to parse it yourself you have to look for keys like this:

/[\n\r]+[\-a-zA-Z]+:/      (a newline followed by a word with no spaces and a colon)

Everything after the colon and before the next key will become the value for that key.

  • However bear in mind that keys will repeat and the order they appear matters,
  • Some keys are optional and most eml you will find nowadays have plenty of custom Keys,
  • You should double check the values as some will need a decode algorithm to be usable.

If you want to learn more about it you may look into these:

  • ver 822: http://www.ietf.org/rfc/rfc0822.txt
  • ver 1521: https://www.ietf.org/rfc/rfc1521.txt

If you want some working code ready to use you may look here:

  • https://www.npmjs.com/package/eml-format
like image 87
JesusTCS Avatar answered Oct 20 '22 00:10

JesusTCS