Skip to content
Home » Linux » How to Rewrite Return-Path and Sender Address in Postfix

How to Rewrite Return-Path and Sender Address in Postfix

When PHP mail() sent out a message to an external mailbox, the message appeared that the return-path and sender address was [email protected]. Let's see an example which shows the original text of the message:
...
Return-Path: <[email protected]>
...
Received-SPF: none (google.com: [email protected] does not designate permitted sender hosts) client-ip=10.23.58.124;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: [email protected] does not designate permitted sender hosts) smtp.mail=[email protected]

Since apache is a pseudo account in Linux, all messages sent to apache will go to root. Therefore, it might not be a good practice to use apache as the return-path, we'd be better to change the address.

Fortunately, Postifx has rules to rewrite the address at:
Generic mapping for outgoing SMTP mail

Let's see how we rewrite the return-path in Postfix.
  1. Set the parameter smtp_generic_maps to the database /etc/postfix/generic in /etc/postfix/main.cf.
  2. [root@test ~]# vi /etc/postfix/main.cf
    ...
    smtp_generic_maps = hash:/etc/postfix/generic

  3. Map apache to another address no-reply:
  4. [root@test ~]# vi /etc/postfix/generic
    ...
    [email protected]       [email protected]

  5. Create and activate the database.
  6. [root@test ~]# postmap /etc/postfix/generic
  7. Don't forget to restart the service.
  8. [root@test ~]# service postfix restart
    Shutting down postfix:                                     [  OK  ]
    Starting postfix:                                          [  OK  ]

Now, you can test it again. Here was our test email received by Gmail:
...
Return-Path: <[email protected]>
...
Received-SPF: none (google.com: [email protected] does not designate permitted sender hosts) client-ip=10.23.58.124;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: [email protected] does not designate permitted sender hosts) smtp.mail=[email protected]

We succeeded to rewrite the return-path and sender address in Postfix. But, wait a minute. There seems something unfinished. Yes, you're right. you can see that I left [email protected] in the status of:
... does not designate permitted sender hosts
This is a SPF issue. We can go further on this problem of sending a trusted email, please refer to my post for more details:
How to Make Your Mail Trusted by Gmail and Yahoo Mail

How to Make Your Mail Trusted by Gmail and Yahoo Mail

Leave a Reply

Your email address will not be published. Required fields are marked *