Postfix masquerading or changing outgoing SMTP email or mail address

Address rewriting allows changing outgoing email ID or domain name itself. This is good for hiding internal user names. For example:
SMTP user: user-01
EMAIL ID: user@domain.com
Server name: server.domain.com

However when user-01 send an email from shell prompt or using php it looks like it was send from user-01@server.domain.com

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 main.cf file

sudo nano/etc/postfix/main.cf

Append following parameter and save the file

smtp_generic_maps = hash:/etc/postfix/generic

Open /etc/postfix/generic file:

sudo nano /etc/postfix/generic

Add config to change user-01@server01.domain.com to user@domain.com.  Save and close the file.

user-01@server01.domain.com user@domain.com

Create or update generic postfix table.

sudo postmap /etc/postfix/generic

Restart Postfix

sudo service postfix restart

When mail is sent to a remote host via SMTP this replaces user-01@server01.domain.com by user@domain.com mail address.