Skip to content

Instantly share code, notes, and snippets.

@alexanderbird
Created January 30, 2021 04:39
Show Gist options
  • Save alexanderbird/f6361d2287bcb583766496da282b8bbb to your computer and use it in GitHub Desktop.
Save alexanderbird/f6361d2287bcb583766496da282b8bbb to your computer and use it in GitHub Desktop.
Convert .eml file to .html with node
const EmlParser = require('eml-parser');
const fs = require('fs');
const inputFile = process.argv[2];
if (!inputFile) throw new Error("Missing input file path argument");
if (!inputFile.match(/\.eml$/)) throw new Error("Only .eml files supported");
if (!fs.existsSync(inputFile)) throw new Error(`Couldn't find file ${inputFile}`);
const emailFile = fs.createReadStream(inputFile);
new EmlParser(emailFile)
.getEmailAsHtml()
.then(htmlString => {
process.stdout.write(htmlString);
})
.catch(error => { console.log(error) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment