2

I would like to filter my incoming emails in Thunderbird in a way that the attachment (invoice as pdf file) is printed automatically without additional confirmation or pop ups.

The email body should not be printed, only the attached pdf file.

Is there any way to achieve autoprinting of the attached files?

I tried using FilterQuilla, but with this I am only able to print the email itself, not the attachment.

There is a related question here on superuser, however that one asks for bulk/batch printing all attachments of manually selected messages (and has no answers). I want to specifically print the attachment of all incoming emails from one sender email address.

While it would be nice to have a Thunderbird based solution, this is not a requirement. It would be totally OK to use some filters in Thunderbird and forward emails to another email address, which is then accessed by another product.

By the way, I would prefer a free/open source solution.

5
  • There is no support in TB filters and no add-on for that. You will need a commercial product that accesses directly the IMAP server. An example is Automatic Email Manager ($89). Is this interesting as an answer?
    – harrymc
    Commented Nov 4, 2019 at 15:51
  • Consider relaxing the requirement for a thunderbird-based solution. @harrymc mentioned a commercial variant, there are also good chances that existing free mail filtering software can be instantiated to do this. Thus while the question is good to understand and perfectly specific, the only answer might be "write your own plugin"?
    – linux-fan
    Commented Nov 4, 2019 at 19:30
  • Thank you for your comments. It must not be a thunderbird-based solution. Sorry that my question is not clear on that - I will update it soon. It would be totally OK to use some filters in thunderbird and forward emails to another email adress, which is then accessed by another product. By the way, I would prefer a free/open source solution. Commented Nov 4, 2019 at 21:20
  • @harrymc: Automatic Email Manager looks good at a first glance, however it comes with a subscription plan - thus $89 is a one-year-license only. Commented Nov 5, 2019 at 15:35
  • I found another one that is included in my answer.
    – harrymc
    Commented Nov 5, 2019 at 16:28

4 Answers 4

2

Here is my solution to the problem, combining some aspects of the other answers and overcoming limitations of those.

Advantages of this solution:

  • Open source solution, thus also available for commercial backgrounds
  • Really invisible, silent printing. No windows are popping up

The approach combines several steps:

  1. Filtering of emails and extraction of the attachments with Filtaquilla in Thunderbird
  2. A python script to print the files through FoxitReader. Other tools, such as AdobeReader or Ghostscript are not capable of silent printing - a window is visible for AdobeReader for quite a while and even for Ghostscript, a window is popping up.
  3. A scheduled task to run the python script on a regular basis.

Step 1

All emails are filtered in Thunderbird with Filtaquilla (available for Thunderbird 52.0-60.* as of 2019). Filtering for email sender and subject provides enough "security" for now. Emails are moved to an IMAP subfolder (as an archive for later inspection if anything went wrong). Filtaquilla extracts all attachments to a specified folder (C:\invoices). Extraction of attachments is not enabled per default in Filtaquilla - be sure to check the settings of Filtaquilla.

Step 2

Place the following print.pyw in C:\invoices:

import os
import subprocess
import sys
import glob
import time

foxit = "C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe"
script_dir = os.path.dirname(os.path.realpath(__file__))

# get all pdf files
pdf_files = glob.glob(script_dir + "/*.pdf")

# print each pdf and delete it
for pdf_file in pdf_files:
    command = []
    command.append(foxit)
    command.append("/p")
    command.append("/h")
    command.append(pdf_file)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE)
    time.sleep(10) 
    os.remove(pdf_file)

Step 3

In principle, the print.pyw file can be run with Filtaquilla. However, this can result in multiple printing of extracted pdf files if the filter finds more than one email.

To overcome this, a scheduled task (action: run program) is helpful, executed every 10 minutes or so.

  • program/script: "C:\Program Files (x86)\Python36-32\pythonw.exe"
  • arguments: "C:\invoices\print.pyw"
  • run in: C:\invoices\

Please note the missing quotes in the run in field, otherwise the script won't run. It is also important, the script and the extracted files are not located on a network drive!

4
  • dropitproject.com could also be a solution, but I did not investigated it further Commented Nov 11, 2019 at 9:06
  • Does this solution still work for you? I need exactly this, except I'll need to print a password protected pdf file. Could you help me with that?
    – uharsha33
    Commented Sep 16, 2020 at 5:44
  • @uharsha33 Yes, it works. For your problem, you need to investigate how you can open a password protected pdf file in FoxitReader via the commandline. Commented Sep 16, 2020 at 9:23
  • 1
    Worked like a charm. To be brutally honest, I have zero programming experience, I simply read up a bit and added command.append("/pwd") and command.append("password") to the code you provided. Thank you!
    – uharsha33
    Commented Sep 17, 2020 at 17:07
1
  1. Create folder 'AttachmentsToPrint', in FilterQuilla check Save Attachments To & specify that folder
  2. Make a batch/script file that waits 60sec (to give FilterQuilla time to extract attachment before we do something with it), then print file, then delete file
  3. In FilterQuilla check Run Program & specify that batch/script file
  4. Cross your fingers

Commercial software certainly exists for this so the request is VERY possible & easy if purchased. Open-source is likely to be possible, but more complicated than the above even. Here are some links to possibly get you started: https://blog.thomashampel.com/blog/tomcat2000.nsf/dx/print-email-attachments-with-a-raspberrypi.htm https://ubuntuforums.org/showthread.php?t=935489

The problem I'd worry about is without a mail client how do you filter for spam/junk so you don't print that, also a bit worrying extract attachments could possibly cause an infection, but maybe I am just being paranoid

1
+50

You may use a two-step solution if the email server uses IMAP:

  1. Download attachments from new emails to a folder
  2. Monitor the folder for new arrivals and print them

For the first step, you could use a free product such as Mail Attachment Downloader Free Edition, described as:

Mail Attachment Downloader securely downloads and processes all your email attachments at-once based on your search preference. Leave all your mail on your server -- it does not interfere with any other email programs you use today to download your mail. You can setup various filters, like size, file type, who it is from, subject of email, date and time stamp, to specify what you want to download.

For the second step, and once the attached files are stored in the specified folder, you could print all of them using this PowerShell one-liner:

Get-ChildItem -Path 'C:\Temp\tmp2' -File | ForEach-Object { Start-Process -FilePath $_.Fullname -Verb Print -PassThru | %{sleep 10}}

The above requires an installed PDF product that supports the Print verb, for example the free Foxit Reader, where a graphical environment (login) is not required.

This PowerShell script can be stored in a .ps1 file and scheduled to run periodically in the Task Scheduler.

If you are using Adobe Reader, the latest version may stay open after the print. This can be solved by modifying the script to:

Get-ChildItem -Path 'C:\Temp\tmp2' -File | ForEach-Object { Start-Process -FilePath $_.Fullname -Verb Print -PassThru | %{sleep 10;$_} | kill}
4
  • Thank you for your answer, which looks great. I tried to implement this and have two issues: 1. How can I delete the file after printing? I tried ´remove-item´ but it does not work. 2. Is it possible to do this invisible, so without any windows popping up? Commented Nov 6, 2019 at 11:37
  • Sorry, you are right - reinstalling Foxit Reader helped. Invisible Printing is possible now! Commented Nov 7, 2019 at 13:14
  • Is this working now?
    – harrymc
    Commented Nov 9, 2019 at 11:26
  • Yes, but with one little drawback: The powershell windows pops up for a second or so. I came up with my own solution which I am about to post. Commented Nov 11, 2019 at 8:00
1

You could use a (pretty small) python script like the one below, that will connect and get the first message from the sender you specify and print the message to standard output. Then, with munpack (package mpack in Debian) you can get the attachment and process it.

The message parsing can also be done in python, meaning you don't need mpack and your solution would be portable to more environments.

Check imaplib for more options, like removing the message when you are done, or doing other type of searches.

import getpass, imaplib

M = imaplib.IMAP4("yourserver")
M.login("user","password")
M.select("INBOX")
typ, data = M.search(None, 'from','your_sender')

num = data[0].split()[0]
typ, data = M.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][1])

M.close()
M.logout()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .