Question
How to rewrite headers of outgoing mail messages?
For example, change From: [email protected]
to From: "Mailer-Daemon at server.example.com" <[email protected]>
.
Answer
This feature is not yet implemented in Plesk UI, but a feature request can be created on the Plesk UserVoice.
Workaround
As a workaround, use Postfix header_checks
:
-
Connect to the server via SSH
-
Add a
header_checks
entry to the/etc/postfix/main.cf
configuration file (the file specified will contain regular expressions for the rewriting):# postconf -e "header_checks = pcre:/etc/postfix/header_checks"
-
If the file
/etc/postfix/header_checks
does not exist, create it:# [ ! -f /etc/postfix/header_checks ] && >/etc/postfix/header_checks
-
Modify the
/etc/postfix/header_checks
file:-
For example, to rewrite all headers with
From: [email protected]
toFrom: "Mailer-Daemon at server.example.com" <[email protected]>
, add the following line to the end of the file:/^From:[email protected]/ REPLACE From: "Mailer-Daemon at server.example.com" [email protected]
-
To hide server IP address from headers:
/^Received:s+.*/ IGNORE
Note: For more information on regular expressions, refer to the PCRE documentation by php.net .
-
To change Message-ID:
/Message-Id:s+<(.*?)@server.example.com>/ REPLACE Message-Id: [email protected]
-
-
Reload Postfix to apply the enabled
header_checks
:# service postfix reload
If a regular expression was applied to the mail message, a similar line will be appended to the /var/log/maillog
log file:
server postfix/cleanup[21124]: E5CD0225EF9: replace: header From: [email protected] (Mail Delivery System) from local; from=<> to= [email protected]: From: "Mailer-Daemon at server.example.com" [email protected]
Note: For more information on header_checks feature in Postfix, refer to the Postfix documentation .