Home » Postfix » How to block particular file extension attachment in postfix

How to block particular file extension attachment in postfix

Postfix provides Mime header check for all incoming messages. You can restrict on .exe / .bat / .vbs files and block all attachments.
mime_header_checks directive allows you to restrict file extension on your mail server.
On most mail server the first thing that needs to be done is to enable header checks and block dangerous files. To block particular file extension attachment in postfix.
Define mime header checks
Open /etc/postfix/main.cf file:

# vi /etc/postfix/main.cf

Append mime_header_checks directive as follows:

mime_header_checks = regexp:/etc/postfix/mime_header_checks

Save and close the file.
Block attachments
Now open /etc/postfix/mime_header_checks file:

# vi /etc/postfix/mime_header_checks

Append following line:

/name=[^>]*\.(bat|com|exe|dll|vbs)/ REJECT

Save and close the file.
Restart postfix
First create postfix lookup table for mime_header_checks file:

# /etc/init.d/postfix restart

You should see rejected mail log in /var/log/maillog file:

# tail -f /var/log/maillog
Aug 20 14:28:06 server postfix/smtpd[5442]: connect from smtp.domain.com [xx.xx.xx.xx]

About

I am founder and webmaster of www.linuxpcfix.com and working as a Sr. Linux Administrator (Expertise on Linux/Unix & Cloud Server) and have been in the industry since more than 14 years.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Time limit is exhausted. Please reload the CAPTCHA.

Categorized Tag Cloud