Want to subscribe to topics you're interested in?
Become a Member

Email Removing IP From Postfix SMTP Relay

Discussion in 'Domains, DNS, Email & SSL Certificates' started by BamaStangGuy, Feb 20, 2019.

  1. BamaStangGuy

    BamaStangGuy Active Member

    669
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    11:18 PM
  2. wmtech

    wmtech Active Member

    187
    44
    28
    Jul 22, 2017
    Ratings:
    +139
    Local Time:
    6:18 AM
    This is not a default Postfix file at CentOS.

    Here you go:

    Add (or edit) such a line to /etc/postfix/main.cf

    Code:
    smtp_header_checks = pcre:/etc/postfix/anonymize_header.pcre
    Add the following code to the file /etc/postfix/anonymize_header.pcre (create the file if it does not exist):

    Code:
    /^Received:/ IGNORE
    or for more sophisticated matching for example (adapt to your needs):

    Code:
    if /^\s*Received:.*Authenticated sender.*\(Postfix\)/
    /^\s*Received:.*Authenticated sender:(.+)/
      REPLACE Received: from localhost (localhost [127.0.0.1]) (Authenticated sender:$1
    endif
    
    /^\s*X-Enigmail/        IGNORE
    /^\s*X-Mailer/          IGNORE
    /^\s*X-Originating-IP/  IGNORE
    /^\s*X-Forward/         IGNORE
    
    and restart Postfix

    Code:
    systemctl restart postfix
     
  3. BamaStangGuy

    BamaStangGuy Active Member

    669
    192
    43
    May 25, 2014
    Ratings:
    +272
    Local Time:
    11:18 PM
    Neither of those worked. Here is how it looks in the email headers:

    Code:
    Received: from lixxx-xxx.members.linode.com (lixxx-xxx.members.linode.com [xx.xx.xx.xx]) by mxa.mailgun.org with ESMTP id 5c6c5721.7f7f4f295e40-smtp-out-n01; Tue, 19 Feb 2019 19:21:05 -0000 (UTC)
     
    Last edited: Feb 20, 2019
  4. wmtech

    wmtech Active Member

    187
    44
    28
    Jul 22, 2017
    Ratings:
    +139
    Local Time:
    6:18 AM
    This (and all other "Received" headers) will be matched by

    Code:
    /^Received:/ IGNORE
    If it does not work, your Postfix does not apply header_checks to the submitted message. How does the message reach Postfix? Via SMTP (port 25) or submission (port 587) or direct handling at the server (php mail or linux mail?).
     
  5. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    2:18 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    It's because mailgun re-adds the receiving IP (origin server IP), themselves. Only way is to use a smtp service that hides originating IPs like Amazon SES which is what I use. Or setup your own postfix server and use it when you setup server's with postfix relay to your own postfix server and config that postfix server to remove the receiving originating IP and not pass it along (which is what Amazon SES mail server does - choose not to pass along the originating IP to destination email targets).
     
  6. wmtech

    wmtech Active Member

    187
    44
    28
    Jul 22, 2017
    Ratings:
    +139
    Local Time:
    6:18 AM
    If you use an external mail provider (Mailgun): Almost all of them are adding the IP from where the mail was received to the headers for SPAM protection and security reasons.

    I did not even know that SES allows to hide this IP.
     
  7. eva2000

    eva2000 Administrator Staff Member

    58,893
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    2:18 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Yup it's hidden by default :) You can verify the email source headers for emails and newsletter sent from this forum's Amazon SES smtp setup :) Only IP you will find in those email source headers is Amazon SES smtp server's IP. Originating server IP is removed. Hence why I always use Amazon SES especially if you have Cloudflare in front of server and don't need for server's real IP to leak :D