In this case we have created a hMailserver script that:
- Checks for a specific email address ("firstname.lastname@example.org");
- Checks a specific Subject field ("[pdfprint]");
- Checks for PDF attachment and if there is one, extract and print it.
To print the PDF, you need to have an app that renders PDFs and prints them. We are using Sumatra PDF, which has a command line interface that exactly does the job.
- Create a new hMailserver user that will be used as a stub to receive the PDF print emails. Enter a long random password and forget it;
- Install Sumatra PDF. Take care of the location of the x86 or x64 version;
- Modify Eventhandler.vbs of hMailserver with the code below.
- Emails to "email@example.com" will be discarded (not stored). You will see:
"APPLICATION" 2284 "2016-08-28 08:48:37.699" "SMTPDeliverer - Message 119900: Message deleted. Action was taken by script subscribing to OnDeliveryStart."
" in the hMailserver eventlog;
- You can address multiple printers (e.g. 2-side, b/w, color)) by adding additional Subject field markers and catch those in the script. Read the Samatra PDF documentation how to connect to specific printers;
- You can add other attachment extensions (e.g. PNG, BMP, JPG, TXT, DOCX etc.) but then you need an app with a command line interface that is able to print the (extracted) file;
- You can set a rule to forward your emails that have the PDF print Subject marker ("[pdfprint]"). The email will stay in your email box while the PDF attachments are printed anyway
- Now you can use even your tablet (Android, iPad) or Smartphone (BB, WP8, WP10, Android, iPhone) to print PDF right from your email app;
- You can have much more checks like attachment size and filename , sender's email domain, etc. Let your fantasy flow!
dim wsh, fso, i
dim AttachmentName, AttachmentType, tempAttachementName, tempFolder, objAttachement
if oMessage.Attachments.Count > 0 then
For i = 0 To oMessage.Attachments.Count-1
set objAttachement = oMessage.Attachments(i)
AttachmentName=tempFolder & "\" & objAttachement.Filename
Select Case lcase(AttachmentType)
Call WriteLogfile("Processing PDF attachment: " & AttachmentName)
if lcase(oMessage.To) = "firstname.lastname@example.org" and _
Instr(lcase(oMessage.Subject),"[pdfprint]") > 0 then
Call WriteLogFile("Printing PDF file for: " & oMessage.From & ", PDF file:'" & AttachmentName)
s="""C:\Program Files\SumatraPDF\SumatraPDF.exe"" -print-to-default " & chr(34) & AttachmentName & chr(34) & " -silent -exit-when-done"
Call WriteLogfile("PDF print message processed.")
fso.DeleteFile AttachmentName ,true