Block Attachments in Postfix
One of our clients requested that we block specific email attachments that come in – their large network was starting to suffer under the storm of non-work emails flying around the company – funny video clips, songs, etc, etc. Not only that, several gullible people had infected their PCs with viruses and malware.
Luckily, blocking specific mail attachments in Postfix is pretty straightforward and only takes a minute or two to set up.
Step 1:
First, we’ll need to activate the header checker in postfix. Make sure the mime_header_checks option is uncommented in main.cf and looks like this:
mime_header_checks = regexp:/etc/postfix/mime_header_checks
Naturally, /etc/postfix/mime_header_checks is the location of file that contains the info on the blocked attachments.
Step 2:
Create /etc/postfix/mime_header_checks, then add in the following content:
/^\s*Content(Disposition|Type).*name\s*=\s*”?(.+\.(mov|mpg|mpeg|avi|wmv))”?\s*$/ REJECT Files attached to emails that contain or end in “$3″ are prohibited on this server as they may contain viruses. The file named “$2″ was rejected
Note that I couldn’t wrap the above in <pre></pre> tags as the formatting looked stupid, also that all goes on one line. Anyway, the file types to be blocked go in the brackets containing ‘mov|mpg…’, and each one is seperated by a pipe (”|”).
Restart Postfix, or get it to reload the configuration files, and there you have it! Whenever a forbidden file attachment is detected (based on the MIME type), it is removed and the message is added to the email information the recipient of this.
Posted in Linux