Stripping attachments with Postfix

With MSH Traffic Policy you can use attachment filtering to apply filters at the server level to control the attachments that users receive. Attachment filtering is increasingly important in today’s environment, where many attachments contain harmful viruses or inappropriate material that may cause significant damage to the user’s computer or to the organization.

This milter software will remove attachments from the email messages and replace them with links to the attachments on ftp or network drive, allowing easy access to files while keeping mailboxes smaller. Bare Postfix don’t provide this kind of functionality out of the box, third party tool is needed.

Application provide Strip Attachments action which allows extracting any attachments from the incoming messages and save them to shared location. Filtering can be based on file name, file extension, MIME type, file size or attachments count. Attachments can be removed from all messages or only from emails specified by scope of senders or recipients.

Built in attachments processor will skip digitally signed, encrypted and rights protected e-mail messages. If exporting attached files is not necessary then other actions can be used:

  • block whole message and attachments
  • delete attachments but allow message through
  • silently delete message and attachments
  • reject email message

Using Strip Attachments action

Before we create our rule, template notification is needed. We can create the template in Html or Text format.

Select Templates tree node and click Add button. In the template definition window provide name and body template, in Html format provide html source code. In template body $MSGID variable can be used, it will be replaced with message identifier, it is used when creating separate directories for attachments.

After adding two template formats you will have result like this (Attachments Stripped html and plain text entries).

Now we can create our rule for archiving messages on network disk. Create rule group and add new rule. On Actions tab click button Add and select Strip Attachments action.

In Directory path field provide absolute path on server where to automatically save attachments. I.e /var/attachments. From Text and Html template choose our previously created templates. Click OK button.

On Conditions tab click button Add and choose Attachments count requirement. Provide your values. I have used grater or equal to 1 condition.

With this condition from all messages outgoing or incoming attachments will be stripped. So for real life scenario it is good idea to define other conditions, like detach attach only from incoming messages.

Define rule name and click OK button. Save all settings and you are ready to test rule.

Testing rule

Send from one user to another test message with couple of attachments. Below you will find result from our example. When recipient will click on provided link he will be redirected to our provided location (of course it should be configured as ftp or network share).

So if you need to remove, strip, detach, delete, dump attachments and insert advisory notice into message for recipient then MSH Traffic Policy will do it for you.

To learn more visit MSH Traffic Policy website.

Lukasz is a software developer and owner of MSH Software company which builds email processing tools for Microsoft Exchange, Zimbra Collaboration Suite and Postfix. He specializes in server, desktop and web applications written in Java, .NET and C++.