Skip to content

Instantly share code, notes, and snippets.

@FrancoMuniz
Last active March 22, 2022 18:36
Show Gist options
  • Save FrancoMuniz/4a37c3f8b8a7a91d6e4ed68202ae0330 to your computer and use it in GitHub Desktop.
Save FrancoMuniz/4a37c3f8b8a7a91d6e4ed68202ae0330 to your computer and use it in GitHub Desktop.
Convert EML to HTML
const fs = require('fs');
const simpleParser = require('mailparser').simpleParser; //Remember to do npm install mailparser
const myFile = "myEmail.eml" // Replace this with your .eml file
var eml = fs.readFileSync(myFile, "utf-8");
simpleParser(eml).then(parsed => {
htmlFile = parsed["html"]
htmlFile = htmlFile.replace(/\\r/g, ''); //This removes all "\r"
htmlFile = htmlFile.replace(/\\n/g, ''); //This removes all "\n"
htmlFile = htmlFile.replace(/\\/g, ''); //This removes all "\"
fs.writeFileSync("emailHtml.html", htmlFile); //Here's your HTML file. You can change the name if you wish
})
@FrancoMuniz
Copy link
Author

Requirements:

npm install mailparser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment