I have an email message in my IMAP inbox. It's HTML email that makes use of fonts, tables, images and such. How do I convert this email message into a PNG image that looks reasonably close to what I see in my email program?

I can almost accomplish what I want by printing to PDF in my email program and then using pdftoppm -png to convert it to PNG. However, the PDF has page margins that the original email doesn't have. Also, pdftoppm produces one PNG per page whereas I'd like to have the entire email in one PNG with no page breaks.

Taking a screenshot isn't an option because the email is very long.

Since HTML email is basically HTML, is there some method that involves getting the raw HTML out of the message and piping it to some kind of WebKit-based rendering tool?


Ended up doing this:

  1. Save the message to message.eml.
  2. Convert .eml to .html using this Python 3 script:
    import email
    import sys

    msg = email.message_from_file(sys.stdin)
    for part in msg.walk():
        if part.get_content_type() == "text/html":
  1. Run the script: python3 eml-to-html.py < message.eml > message.html

  2. Open the resulting message.html in Firefox.

  3. In the Firefox menu, choose Tools > Web Developer > Developer Toolbar to show a command line at the bottom of the browser window. Type screenshot --fullpage message.png there and press Enter (as per Journeyman Geek's suggestion).

  • ooh. is email a standard python module you'd find or does it need an additional package? – Journeyman Geek Apr 15 '17 at 22:50
  • It's standard: docs.python.org/3/library/email-examples.html Quite big and hard to understand, but there are lots of examples on Stack Overflow and elsewhere :) I tried to find a ready-made command-line tool to convert .eml to .html but couldn't. – Lassi Apr 17 '17 at 8:32

If its a one-shot thing - firefox does this awesomely. Shift f2 opens up a console, and the command screenshot --fullpage filename shows your screen exactly as you see it. Might need some work if its in a frame.

Not sure if its trivially automatable but it works quite well otherwise.

  • On my system, shift-f2 doesn't work, but Ctrl-Shift-K open the console. From there, though, entering the command produces an error message: SyntaxError: missing ; before statement. Prefixing it with a semicolon still produces the message. – fixer1234 Apr 22 '17 at 4:03
  • That's odd. The console is a very standard built in thing – Journeyman Geek Apr 22 '17 at 4:05
  • 1
    OK, it isn't the console, it's the developer toolbar (although it might work from the console with proper settings; fullpage not available on cmdline w/o it). The menu on mine says shift-f2 should work, so there might be some kind of add-on conflict, however, it is accessible from the menu: Tools | Web Developer | Developer Toolbar. You need to access the settings cog icon and select Fullpage Screenshot. You can use the built-in camera icon to take the screenshot. Info: developer.mozilla.org/en-US/docs/Tools/GCLI and developer.mozilla.org/en-US/docs/Tools/Taking_screenshots – fixer1234 Apr 22 '17 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.