Remove sensitive (personal) headers from postfix emails

When I first set up my email server to handle messages for my domains, I noticed a concerning issue: the outgoing email headers included sensitive information, such as my home IP address and the hostname of the device sending the mail. Yikes! That’s not just a privacy concern—it’s an open door for anyone to track my location or fingerprint my setup.

Thankfully, Postfix is highly configurable, and removing these details from outgoing emails is straightforward. Let’s dive into how to clean up your outgoing email headers and why each step is important.

What Are Email Headers, and Why Should You Care?

Email headers contain metadata about your emails, such as the sender, recipient, subject, and the servers the email passed through. These headers also often include extra details like:

  • The IP address of the sending device
  • The software used to send the email (e.g., mail clients or relays)
  • Hostnames and timestamps

While some of this data is essential for email delivery, much of it isn’t—and exposing your personal IP address or computer hostname can be a major privacy issue. For example:

  • Privacy Risks: Your IP address could reveal your general location or internet provider
  • Security Concerns: Hostnames can leak details about your setup, helping attackers craft targeted attacks
  • Professionalism: Emails with extra headers like X-Mailer or User-Agent can look unpolished or amateurish

Luckily, Postfix allows you to customize which headers are included in outgoing emails, and that’s exactly what we’ll do.

Cleaning Up Outgoing Headers in Postfix

Step 1: Enable Header Checks in main.cf

Postfix’s main configuration file is located at /etc/postfix/main.cf. Open it with your favorite text editor: nano /etc/postfix/main.cf

Look for the section where other header-related options are defined (or add these lines near the bottom if you're not sure):

# Enable custom header checks for outgoing emails
smtp_header_checks = regexp:/etc/postfix/smtp_header_chec

This tells Postfix to use a custom set of rules to inspect and modify headers for outgoing emails.

Step 2: Define the Headers to Remove

Now, let’s create the file that specifies which headers to strip. This file will contain regular expressions (regex) that match specific headers and instruct Postfix to ignore them.

Create the file smtp_header_checks inside the postfix config: nano /etc/postfix/smtp_header_checks Add the following lines:

/^X-Mailer:/            IGNORE
/^X-Mailer-Type:/       IGNORE
/^User-Agent:/          IGNORE
/^Received:/            IGNORE
/^X-Original-IP:/       IGNORE

Here’s what these rules do:

  • /^X-Mailer:/: Removes the header indicating which mail client or software sent the email
  • /^X-Mailer-Type:/: Removes another optional header that could expose sensitive software details
  • /^User-Agent:/: Eliminates details about the email client (e.g., Thunderbird, Outlook)
  • /^Received:/: Strips server information about the path the email took (useful for privacy)
  • /^X-Original-IP:/: Removes the sender's original IP address

Each line uses regex to match a header and IGNORE tells Postfix to exclude it from the email.

Step 3: Apply the Configuration

To make Postfix recognize the new rules, we need to compile the file into a database Postfix can use: postmap /etc/postfix/smtp_header_checks Finally, restart Postfix to apply the changes: systemctl restart postfix

From now on, outgoing emails will no longer include the sensitive headers specified in smtp_header_checks.

Testing Your Configuration

After making these changes, it’s a good idea to send a test email and inspect the headers. You can do this by sending an email to another email service (such as gmail) and copy the headers there. From there you can use a tool such as MxToolbox to show which headers are still visible and in your emails. If you have done everything correctly it should look like this: enter image description here