Postfix: Add Custom Header

image_print

The file /etc/postfix/header_checks does the trick.

main.cf

It has to be included to main.cf first

vi /etc/postfix/main.cf

Add a line like

smtp_header_checks = regexp:/etc/postfix/header_checks

Save and exit the editor.

header_checks

Now open the file header_checks and add your regexps.

Use the PREPEND operator to add a custom header to your emails.

The prepended text is output on a separate line, immediately before the input that triggered the PREPEND action.

Example:

/^From:/i PREPEND X-DKIM-Options: s=k1; i=user@domain.xx

This will add the line

X-DKIM-Options: s=k1; i=user@domain.xx

immediately before the line beginning with From:.

Add as many custom headers as you need. There are many more actions than PREPEND as explained in man 5 header_checks.

postmap

Rebuild the database with

postmap hash:/etc/postfix/header_checks

and

restart postfix

service postfix restart

Debug

If the postfix header_checks are not working or set twice, then propably receive_override_options are set incorrect, either in main.cf or in master.cf.

grep -R receive_override_options /etc/postfix

Test also with

postconf -n