Applicable to:
- Plesk for Linux
Question
How to rewrite headers of outgoing mail messages?
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 not yet implemented in Plesk UI, but a feature request can be created on the Plesk UserVoice.
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
7 comments
Hi,
Is it possible to prevent outgoing mails marked as Spam with header_check? A lot of customers forward mails to extern mail addresses and make us a problem.
Regards,
Miomir
Hello @Miomir Besarabic,
As I can see the case has been already discussed in the following article https://support.plesk.com/hc/en-us/articles/115000786914
Here is your reply:
-----------
The best solution was Spamassassin pre-queue filtering, which cover everything and allow to reject Spam or unwanted mails. Pre-queue filtering is simple to implement with Postfix and header_checks (on Linux). I did on our test server with just few changes in 2 files.
-----------
Glad to hear the solution is found.
If you have any additional questions, let us know.
pcre does not work for me. I use regexp.
Adding the "/^Received:s+.*/ IGNORE" makes Plesk add a second Date header. This behaviour started at Obsidian, had this rule work for Plesk Onyx a few weeks ago. Any suggestions on how to fix this?
Do not use IGNORE. Use REPLACE and this issue will be fixed.
Hi Clemens Mol,
I've just tested it on our test environment and it hasn't added a second date header as you can see below:
Are you sure your Postfix configuration is by default and has no customizations?
In any case, in order to investigate, it would be better if you open a new support request.
For me, contrary to what is stated in the article, Postfix also applies the configuration to incoming mail and not only to outgoing mail. If only outgoing mails should be taken into account, the parameters should not be entered in main.cf, but in master.cf. Which concrete parameters would have to be entered for this, so that Plesk can also work with it?
Please sign in to leave a comment.