Skip to main content

Block Risky Attachments in Zimbra: Programs, Archives and Office Macros

Most malware still arrives the old way: an "invoice" that is really a program, a ZIP file with a script inside, or a spreadsheet that asks to enable macros. Nobody needs to receive programs by email, so the simplest defence is to refuse them, wherever they are hidden. With MSH Zimbra Rules, two policy rules do it on the server, before the message reaches any mailbox: one refuses programs and scripts, the other removes macro-enabled Office files and tells the reader why.

What you get​

AttachmentWhat happens
invoice-2026-114.exeThe message is refused with 550 5.7.1
shipping-documents.zip with setup.exe insideThe message is refused, the archive is checked
A ZIP with statement.pdf that is really a Windows programThe message is refused, the file is recognised by its content
budget-2027.xlsm next to agenda.pdfThe .xlsm is removed, the rest is delivered with a banner
agenda.pdf, photo.jpg, contract.docxDelivered as usual

The reader of a message that lost a macro file sees this in the Zimbra web client:

A message from James Carter to Aisha Okafor in the Modern Zimbra web client, with only agenda.pdf attached and a yellow banner Attachment removed: A macro-enabled Office file was removed from this message for your safety. Ask the sender for a PDF, or for a .docx or .xlsx file without macros

What you will build​

A policy rule group Attachment security with two rules:

RuleConditions (any)Actions
Programs and scriptsAttachment name is a program or a script; or an archive holds oneBlock, custom 550 5.7.1 with the reason
Office macrosAttachment name ends in .docm, .xlsm, .pptm or a macro templateRemove by name, and Add message banner

The rules have no direction condition, so they guard incoming, outgoing and internal mail alike: a colleague's infected laptop is as much a risk as a stranger.

Before you start​

  • MSH Zimbra Rules 1.4 or later, installed on the Zimbra server, see the installation guide.
  • The Message Notices zimlets, for the banner in the web client, see Zimlet configuration.
  • Harmless test files named like the real thing: a text file renamed to invoice.exe, a ZIP file with a text file renamed to setup.exe inside, and a text file renamed to budget.xlsm. Never test with real malware.
  • A way to share files that are blocked by email, such as a file share or a download link, so the reject message can point people to it.

Step 1 - Refuse programs and scripts​

Open Rules > Policy Rules, click Add Group..., name the group Attachment security and save it. Double-click it, click Add Rule... and name the rule Programs and scripts.

On the Conditions tab add two conditions and choose Any condition is met:

  1. Attachments > Name, Regular expression, with the file types Windows runs:

    .*\.(exe|com|scr|pif|bat|cmd|msi|js|jse|vbs|vbe|wsf|hta|ps1|lnk|jar|iso|img)$
  2. Attachments > Archive content. It comes filled with the same kinds of file types. On its Options tab tick Also match files that are executables by their content, whatever their name, so that a program renamed to statement.pdf inside an archive is caught too. See Archive content.

On the Actions tab add Message > Block, Type Custom, 550, 5.7.1 and a reason the sender can act on, for example Rejected: programs and scripts are not accepted as attachments. Share the file through a download link. Click Save.

The Policy Rules page with the Add Group button
Step 1 of 12

In Rules > Policy Rules, click Add Group... and name the group Attachment security.

A rejected incoming message bounces back to the sender with your reason, so a business partner learns why and how to send the file instead. For a user of your own, see If senders do not understand the refusal.

Step 2 - Remove Office macros, keep the message​

Macro-enabled Office files are legitimate in some companies and dangerous in most. Instead of refusing the whole message, take out just that file and deliver the rest.

In the same group click Add Rule... and name the rule Office macros.

  • Conditions: Attachments > Name, Regular expression:

    .*\.(docm|xlsm|pptm|dotm|xltm|potm)$
  • Actions: first Attachments > Remove by name with the same pattern and Regular expression, then Zimlets > Add message banner: Level Warning, Icon paperclip, Badge Attachment removed, and a Text that tells the reader what to do, for example A macro-enabled Office file was removed from this message for your safety. Ask the sender for a PDF, or for a .docx or .xlsx file without macros.

Click Save. See Remove attachments by name and Add message banner.

The General tab of the new rule Office macros with a description
Step 1 of 8

Add a second rule to the group, Office macros.

Step 3 - Test it​

Send test messages in the Rules tester: New message

Custom..., a sender from outside, one of your users as the recipient, and the test files on the Attachments tab. Then open each message and its Processing trace.

The trace of a message with invoice-2026-114.exe: the regular expression matches the name, Conditions match (type:any), block message applied
Step 1 of 4

invoice-2026-114.exe: the name matches, the message is refused.

Then send a real message with the .xlsm and a PDF from one user to another in the web client. It arrives with the PDF only, and the banner above the text:

A new message in the Modern Zimbra web client with budget-2027.xlsm and agenda.pdf attached
Step 1 of 2

A message with the macro file and a PDF.

If senders do not understand the refusal​

When one of your own users sends a program, the Zimbra web client only says Could not send message, without the reason in your Block action. Add a New message action to the rule that explains the refusal to the sender, as in Stop Card Numbers from Leaving Zimbra by Email. Senders outside get a bounce with the reason from their own mail server.

Variations​

  • Archives you cannot look into. On the Options tab of Archive content, choose Treat them as a match under Archives whose content cannot be listed to refuse encrypted 7z and RAR archives as well. Password-protected ZIP files usually still list their file names and are checked by name.
  • Password-protected attachments. The Attachments > Encrypted condition matches them, see Attachment encrypted.
  • Allow a department. If IT needs to receive installers, add an exception Recipients with their group to the Programs and scripts rule.

What these rules do not do​

  • They are not a virus scanner. A PDF or a Word file without macros can still carry an exploit. Keep the antivirus of Zimbra running.
  • They judge names, and content only inside archives. A program attached directly under an innocent name is caught by Archive content only when it is inside an archive. Pair the rules with the antivirus for that case.

Want to try it on your own server? Start a free trial.