How do I convert an HTML email saved as a text file to a PDF file from the Linux command line?

1

I need to be able to convert HTML email messages saved as text files (.eml or .msg) to PDF documents, one PDF per email, retaining formatting and images.

Are there any Linux tools that will allow me to do this from the command line (so it can be scripted)?

Stacey Richards

Posted 2011-08-23T02:29:40.673

Reputation: 1 292

Question was closed 2015-02-06T03:16:40.487

Answers

3

.eml files are just text files, so you can print them using standard methods.

The easiest utility for text conversion is arguably Pandoc. This utility should cover any html email as well, although you'll want to specify the format manually since .eml isn't very standard when it comes to text data.

pandoc -f html -o outputfile.pdf inputfile.eml

digitxp

Posted 2011-08-23T02:29:40.673

Reputation: 13 502

Pandoc didn't work for me, I encountered pandoc: Error producing PDF from TeX source even after installing 1GB of dependencies. I instead used MHonArc which was easy to use too and available in most all package installers. apt-get install mhonarc' and then you can convert an entire mailbox/folder or even a single file likemhonarc -single somemailfile > converted.html`

– TryTryAgain – 2015-11-04T20:08:55.843