Applicable to:
- Plesk for Linux
Question
How to rewrite headers of outgoing mail messages on a Plesk server?
For example, change From: MAILER-DAEMON@server.example.com
to From: "Mailer-Daemon at server.example.com" <MAILER-DAEMON@server.example.com>
.
Answer
This feature is yet to be implemented in Plesk UI.
Warning: You must make sure that the postfix-pcre
package is installed on your Linux server before following the steps below, because if it is not, the pcre (Perl Compatible Regular Expressions) rules we need to add to the /etc/postfix/header_checks
will not be interpreted correctly by the postfix mail server and that will cause mail delivery issues.
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: MAILER-DAEMON@server.example.com
toFrom: "Mailer-Daemon at server.example.com" <MAILER-DAEMON@server.example.com>
, add the following line to the end of the file:CONFIG_TEXT: /^From:\s+MAILER-DAEMON@server.example.com/ REPLACE From: "Mailer-Daemon at server.example.com" MAILER-DAEMON@server.example.com
-
To hide server IP address from headers:
CONFIG_TEXT: /^Received:\s+.*/ IGNORE
Note: For more information on regular expressions, refer to the PCRE documentation by php.net .
-
To change Message-ID:
CONFIG_TEXT: /Message-Id:\s+<(.*?)@server.example.com>/ REPLACE Message-Id: $1@example.com
-
-
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:
CONFIG_TEXT: server postfix/cleanup[21124]: E5CD0225EF9: replace: header From: MAILER-DAEMON@server.example.com (Mail Delivery System) from local; from=<> to= user@example.com: From: "Mailer-Daemon at server.example.com" MAILER-DAEMON@server.example.com
Note: For more information on header_checks feature in Postfix, refer to the Postfix documentation .
Comments
1 comment
Hi Mikhail Shport,
When placing the call via:
What I get is:
Can you please see, what a fix is required?
Could it be you missed the mapping of it?
Install PCRE for postfix?
And yet... it doesn't work. Is it called "on time" before the email is finalized?
Please sign in to leave a comment.