Postfix block PDF or ZIP files attachments

Q. How do I block all PDF or ZIP files attachments under Postfix Mail Server?

A. You can easily block email attachments using mime header check.

Open postfix config file

Login as the root, enter:
# vi /etc/postfix/main.cf

Block zip or pdf files

Use mime_header_checks postfix config directive, enter:
mime_header_checks = regexp:/etc/ostfix/block_attachments
Save and close the file. Open /etc/ostfix/block_attachments file and append code as follows:
/name=[^>]*\.(pdf|zip)/ REJECT
Save and close the file.

Restart Postfix MTA

You must restart or reload postfix:
# /etc/init.d/postfix reload


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Mustafa Sep 20, 2011 @ 14:08

    Hi,
    This will block attachments for all the accounts on the server, what I want to do is block all outgoing attachments for one account.
    Is there is a way to do that ?

  • Itelica Apr 26, 2013 @ 8:19

    This worked for us, thanks. Just one thing, you have missed out the P in postfix in the regexp line entry. We noticed it and changed it but others may not.

  • Ramesh Jul 23, 2014 @ 17:08

    Hi,

    Please advice me how to block zip file include exe in postfix.

    Thanks for advance
    Ramesh

  • dxman Aug 15, 2014 @ 12:32

    hi admin,
    i am not getting bounce back email if the user tried to send email with the ( exceeded quota )attachment. mail deliver to recipient but the attachment is drop by server (if attach using the outlook)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum