Search code examples
emailpostfix-mta

Postfix generic rewrites receipent addres


How to prevent generic maps to rewrite receipent address? My generic looks like:

name1@domain.com devs@domain.com
name2@domain.com devs@domain.com

If I send mail from name1@domain.com to name3@domain.com generic rewrite from field and put devs@domain.com as a sender. It is completely OK. But if I send mail from name1@domain.com to name2@domain.com, message with devs@domain.com is sent to devs@domain.com (recipient is overwrited also). Can I prevent this?

main.cf row: smtp_generic_maps = hash:/etc/postfix/generic


Solution

  • I've solved this. Instead of generic maps, I put into main.cf next lines:

    sender_canonical_classes = envelope_sender, header_sender  
    sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps  
    smtp_header_checks = regexp:/etc/postfix/header_check
    

    In file /etc/postfix/sender_canonical_maps:

    /.+/    devs@domain.com
    

    And in file /etc/postfix/header_check:

    enter code here
    /From:.*/ REPLACE From: devs@domain.com
    

    After that, execute:

    enter code here
    /etc/postfix/#postmap sender_canonical_maps  
    /etc/postfix/#postmap header_check
    

    And restart postfix, and voila!