Automate Print to PDF



I would really like to utilize the Print to PDF feature on select downloaded emails that I export from Mailpile, via. automation, just like it would look like if I did Print to PDF on an email in GMail. However, it appears that only basic text type exports are possible to export from Mailpile. Ideally, I would like to print emails to PDF’s so that I can stash what the original email looked like (including the ability to select text) in a contained, isolated file.

Is there any way that you can think of for me to do this? I am a programmer if that makes a difference, though I don’t want to spend hours constructing something complex (the whole point of this is to automate things so that I don’t have to spend time on it).



Hello! When you say “the Print to PDF feature”, which feature do you mean? Do you mean the feature in the browser? The OS print dialog?

The problem with this, is something has to render the mail to something that can then be printed. Mailpile generates HTML pages, which the browser then knows how to render visually, and that rendering can be printed. The only good way I can think of to automate this, is something involving selenenium or some other programmable headless browser.

The script controlling the headless browser could periodically perform a search for a specific tag, and then use the headless browser to download and print the messages. It could then also untag the messages, or add another tag marking them “printed,” to avoid reprinting the same message multiple times.

Then you, as the user, just have to tag the messages you want printed.

The main downside today, is you’ll have to give the controller script a copy of your Mailpile password so it can log in. Allowing the user to create per-app login credentials (potentially with restricted access) is on my TODO, but I cannot promise when that will be available.

This is a fair bit of work, but it is doable. Unless you are very familiar with such tools (I assume not, otherwise you wouldn’t be asking), I’d estimate this to be days of work, not hours.


Good answer, thank you.

Perhaps there could simply be a way to export the html that we see in Mailpile, like GMail does when you tell it to print? Instead of showing it to the user, there could be a way to automate the export of this HTML to a standalone file, which could then be converted to PDF, one way or another? (But even having it as standalone HTML would be an improvement.)