Sendmail:

# cd /etc/mail
# vi /submit.mc
…
LOCAL_CONFIG
HX-MyCustomHeader: MyCustomHeaderValue
…

# m4 submit.mc > submit.cf
# service sendmail restart

Postfix:

# cd /etc/postfix

Note: In the master.cf, only the -o (options) line was added.

# vi master.cf
…
smtp unix – – n – – smtp
-o smtp_header_checks=regexp:/etc/postfix/mycustomheaders
…

Create a file to store your custom headers.

# vi mycustomheaders
/^Subject:.*/ PREPEND X-MyCustomHeader: MyCustomHeaderValue

# service postfix restart