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