This post shows how to set up a rule that unzips an email attachment, converts each file inside to PDF (or removes a PDF’s password), and then runs a script on the result. It is written for version 4.0.
Which edition you need:
- Unzip, Run a script and Run a command line need PRO Rules Server.
- Convert documents is in PRO Rules Client and up. PRO Rules Client converts to PDF only, which includes removing a PDF’s password. PRO Rules Server also converts to other formats, such as Word or multi-page TIFF.
You start from a rule with its conditions and its Save part set up, for example for the emails from acme.example, saved to \\fileserver\Finance\Invoices. New to rules? See save emails and attachments to folders.
Steps work on the saved files. To run them on the email itself too, set What to save to The email and its attachments: the email is then saved as an .eml file, and Convert documents can turn it into a PDF.
1. Unzip the attachment
In the Rule Editor, click Add a step…, find Unzip (type “zip” in the search box) and click Add. It goes under Then. Its options:
- Only these files: one file name or extension per line, such as
.docxand.pdf. Leave it empty to unzip every file. - Delete the zip file after unzipping it, if you only want the files inside.
- Keep the folders inside the zip, to keep the zip’s own folders.

2. Convert each unzipped file, inside Unzip
Steps inside the Unzip step run for each file it unzips. To add one there:
- Select Unzip in the rule’s outline.
- Click Add a step… and, in the Add it: box, choose Inside “Unzip”.
- Pick Convert documents and click Add.
In the Convert documents step, click Add… to add a conversion. In the Conversion window, choose what is converted in From:, choose pdf in To:, and set the result’s name in Save as:, such as {SAVE_PATH}\{FILENAME}.pdf. Add one conversion for each kind of file, for example Word files and pictures. Tick Delete the originals after converting them if you only want the PDFs.

Decrypt a PDF
Do the files arrive as password-protected PDFs? Add a conversion from PDF to pdf, with a new name in Save as: such as {SAVE_PATH}\{FILENAME}_open.pdf. Under A PDF converted, type the password in Decryption password:. The PDF it saves has no password. Remove the restrictions also drops limits such as no printing or no copying. It works the other way too: Encrypt the PDF, under The PDF made, adds a password to the PDFs you make.

3. Run a script on the converted file, inside Convert documents
Now select Convert documents, click Add a step…, choose Inside “Convert documents” in the Add it: box, and pick a step from Programs:
- Run a script runs a script with the fields and waits for it to finish. Set the Program: (a .bat or .exe file, or
powershell.exefor a PowerShell script), its Arguments: and a Timeout (seconds):. What it prints goes to the program’s logs. - Run a command line runs a program or a .bat file with the fields: set the Command: and its Arguments:.
Click Fields… to add fields to the arguments. Inside Convert documents, {SAVE_PATH} and {FILENAMEEXT} are the converted PDF, not the zip or the file it was made from. For example, with powershell.exe as the program, the arguments could be -File "C:\Scripts\ArchiveInvoice.ps1" "{SAVE_PATH}\{FILENAMEEXT}" "{EMAIL_FROM}".
Run: says whether the step runs For each saved file or Once per email. Click Run it once (test) to try it with a sample email’s values.

The finished rule
The rule’s outline now reads:
- Then
- Unzip
- Convert documents
- Run a script
- Convert documents
- Unzip
Each zip is unzipped, each file inside is converted to PDF, and the script runs once for each PDF.

Click Test this rule… to try it on emails you pick. Unzipping and converting are done for real, into a temporary folder, so you can open the PDFs. The script is only described, not run. Then click Save.
A step can fail, for example when a PDF’s password is wrong. Steps under If something fails, such as Move or copy the email or Send notification, tell you or set the email aside. The program also tries a failed step again by itself. See nesting email rules and actions.
More steps for files
Other steps go well with these: Convert all files to a single PDF, Merge PDFs, Split PDF and Make PDFs searchable (OCR) (PRO Rules Server), and Upload to cloud or Copy file (PRO Rules Client and up). Need a step that isn’t there? Contact us and we’ll look at it.
Try it: download Mail Attachment Downloader and start with the free edition, or compare the PRO editions, each with a 30-day money-back guarantee.