Postfix Masquerading or changing outgoing address

Address rewriting allows changing outgoing email ID or domain name itself. This is good for hiding internal user names. For example:

SMTP user: sushant.chawla
EMAIL ID: [email protected]
Server name:

However when sushant.chawla send an email from shell prompt or using php it looks like it was send from [email protected]

In some cases internal hosts have no valid Internet domain name, and instead use a name such as localdomain.local or something else. This can be a problem when you want to send mail over the Internet, because many mail servers reject mail addresses with invalid domain names to avoid spam.

Postfix MTA offers smtp_generic_maps parameter. You can specify lookup tables that replace local mail addresses by valid Internet addresses when mail leaves the machine via SMTP.

Open your file
# vi /etc/postfix/
Append following parameter

smtp_generic_maps = hash:/etc/postfix/generic

Save and close the file. Open /etc/postfix/generic file:

# vi /etc/postfix/generic
Make sure [email protected] change to [email protected]

[email protected] [email protected]

If you want to masquerade the whole domain, add a line:

Save and close the file. Create or update generic postfix table:

# postmap /etc/postfix/generic

Restart postfix:
# /etc/init.d/postfix restart

When mail is sent to a remote host via SMTP this replaces [email protected] by [email protected] mail address. You can use this trick to replace address with your ISP address if you are connected via local SMTP.

Leave a Reply

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