Blocking .exe attachments with postfix or amavisd-new and ISPConfig 3

If you use postfix and / or amavisd-new on the mail server, you can use the following recipes to block emails with executable (exe, bat, scr) attachments.

Block the attachments with a postfix header filter

In ISPConfig, click on "Email in the upper menu, then on "Content filter" in the left menu and click on the "Add new content filter" button. Enter the following details:

Filter:

MIME-Header Filter

Regexp. Pattern:

/^Content-(Disposition|Type).*name\s*=\s*"?(.*\.(bat|exe|scr))(\?=)?"?\s*(;|$)/x

Data:

File extension is blacklisted on this server

Action:

DISCARD

Use amavisd-new to block the emails with executable attachments.

Edit the amavisd configuration file (/etc/amavisd.conf or /etc/amavisd/amavisd.conf)

nano/etc/amavisd/amavisd.conf

and add the following lines:

$banned_filename_re = new_RE(
qr'.\.(bat|exe|scr)$'i,
qr'^\.(exe|zip|lha|tnef)$'i,
);

then restart amavisd-new:

service amavis restart

6 thoughts on “Blocking .exe attachments with postfix or amavisd-new and ISPConfig 3”

  1. Avatar

    .com files should be blocked too.

    Reply
  2. Avatar

    How do you block and send an email only to the recipient? and forward the block email to a specific address like [email protected].

    Reply
  3. Avatar

    Hi, Is it really a file type blocking or only a file extension one?
    I mean in both postfix and amavis-new…

    Thanks

    Reply
  4. Avatar

    i tried to block *.zip, *bat and *.exe using this:

    /^Content-(Disposition|Type).*name\s*=\s*”?(.*\.(zip|bat|exe))(\?=)?”?\s*(;|$)/x

    but it’s not working as clients still can receive attached zip files.

    Reply
    • Avatar

      the same. mime header filter not work

      Reply
  5. Avatar

    Remove “x” from “/x” in the end

    Reply

Leave a Comment

*