Tuesday, February 5, 2013

Block attachments with Postfix

With MSH Attach Filter (freeware) milter application you can block or remove any attachment you want.

You can also:
  • filter by attachment name, content type, size
  • add, remove and compress attachments
  • block message with suspicious files

Block message with certain attachments

First way is to block email containing specified attachments.

You need to define blocking action:

<block-message type="discard"/>

And one condition which will execute block message action. In this example it will block attachments with extensions: bat, com, exe, dll and vbs.

<attach-name value="*.bat;*.com;*.exe;*.dll;*.vbs">

Remove attachments from message

Another solution is to only remove attachments from message without block email.

It is even simpler because you need only define one action. This time it will remove attachments greater than 1 MB:

<attach-remove-size value="1" unit="mb" cmp="gt"/>

This was a simplest configuration when you need to dump attachment from messages.