Postfix Header Checks

Discussion in 'Installation/Configuration' started by dirk, May 11, 2005.

  1. dirk

    dirk New Member

    Hi,

    I've read that Postfix can perform certain actions on emails based on the contents of the email header (header checks). How do I make my Postfix act like that? For example, I want Postfix to delete all emails that have a spam score (from SpamAssassin) of 15 or more. The header of such emails contains a line like this:

    Code:
    X-Spam-Level: ***************
    Thanks,

    Dirk
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Here's a small introduction on Postfix header (and body) checks:
    http://www.postfix.org/header_checks.5.html

    Basically you have to do something like this:
    Code:
    postconf -e 'header_checks = regexp:/etc/postfix/header_checks'
    Now create the file /etc/postfix/header_checks and put something like this into it:
    Code:
    /^X-Spam-Level: \*{15,}.*/      DISCARD
    DISCARD will delete all messages with a spam score of 15 and above. You can choose another action than DISCARD, they are listed in the link I posted at the beginning.

    Finally, restart Postfix:
    Code:
    /etc/init.d/postfix restart
     
  3. dirk

    dirk New Member

    Thanks, Falko.
    For the REDIRECT action, I need Postfix 2.1 or above?

    Dirk
     
  4. falko

    falko Super Moderator ISPConfig Developer

    Yes, that's true, the REDIRECT action is new in Postfix 2.1.
     
  5. Icaro

    Icaro New Member

    I'm having problems with REDIRECT action in header_checks.
    My postfix is version 2.3.8-2+etch1.

    In my main.cf I have:

    header_checks = regexp:/etc/postfix/header_checks

    And the "header_checks" file:

    /^To: .*@(?!mydomain\.com>)/ REDIRECT [email protected]

    The problem is that the emails are not being redirected, only rejected.
    also if I put REJECT "message" instead of REDIRECT the message I put in the REJECT action doesn't appear in the log....so it seems this actions doesn't work well...

    Anyone can help me with this?

    Thanks in advance and excuse my english.
     
  6. falko

    falko Super Moderator ISPConfig Developer

    What's in your mail log when this happens?
     
  7. Icaro

    Icaro New Member

    Hi Falko, thanks for the reply. This appears in my log:

    Mar 12 17:22:51 mail postfix/smtpd[7132]: NOQUEUE: reject: RCPT from cm35140.red.mundo-r.com[213.60.35.140]: 554 5.7.1 <[email protected]>: Relay access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<RNPABFF9A>
     
  8. Icaro

    Icaro New Member

    Falko, I found the error. The regular expression is not working. The message was rejected due to authentication problems. Once I solved these problems the message is sended so the problem I have now is that my regular expression is not working.

    In the log I see lots of messages like this:

    Mar 11 16:23:43 mail postfix/cleanup[21225]: warning: regexp map /etc/postfix/header_checks, line 2: Invalid preceding regular expression

    And the header_checks file is:

    /^From: .*printer@mydomain\.com>/ OK
    /^To: .*@(?!mydomain\.com>)/ REDIRECT [email protected]

    Do you know what's wrong with this file, I'm trying that [email protected] can't send emails outside of mydomain.

    Thans again.
     
  9. sjau

    sjau Local Meanie Moderator

    Hmmmm, I'm also currently looking into that. Is there a way to REJECT all emails in which a given string occurs in any of the headers? This far I can only see examples that check specific headers.

    Would this work:

    *some_string* REJECT?
     

Share This Page