Login or register    


random postfix email server tips and tricks.

Send outbound emails to filesystem

Add the following lines to your /etc/postfix/master.cf:

fs_mail    unix  -       n       n       -       -       pipe
   flags=F user=root argv=tee /tmp/fs_mail.dump

And then add this line to your /etc/postfix/main.cf:

default_transport = fs_mail

And then restart your Postfix server

sudo service postfix restart

Add custom headers with Postfix

In this guide we show how to add custom headers to ever email that arrives to Postfix via SMTP only.

  1. create a user/group named filter with its home dir as /var/spool/filter.
  2. create a file owned by postfix:postfix named /etc/postfix/custom-headers.txt:
X-SES-SOURCE-ARN: arn:aws:ses:us-west-2:myid:identity/my.example.com
X-SES-FROM-ARN: arn:aws:ses:us-west-2:myid:identity/my.example.com
X-SES-RETURN-PATH-ARN: arn:aws:ses:us-west-2:myid:identity/my.example.com
  1. create another file owned by filter:filter named add-custom-headers.sh:

# Simple shell-based filter. It is meant to be invoked as follows:
#       /path/to/script -f sender recipients...

# Localize these. The -G option does nothing before Postfix 2.3.
SENDMAIL="/usr/sbin/sendmail -G -i" # NEVER NEVER NEVER use "-t" here.

# Exit codes from <sysexits.h>

# clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15

# change directory to our temporary directory.
cd $TMP_DIR || {
    echo $TMP_DIR does not exist; exit $EX_TEMPFAIL; }

# accept stdin email() and save it to a file named in.pid.
cat >in.$$ || {
    echo Cannot save mail to file; exit $EX_TEMPFAIL; }

########### Add SES Headers to email. ###########
sed -i'' -e "/Date: /r /etc/postfix/custom-headers.txt" in.$$

# pass the email back to postfix using the sendmail command.
$SENDMAIL "$@" <in.$$

# exit with error code from sending to sendmail, run trap cleanup.
exit $?
  1. define our new filter in /etc/postfix/master.cf:
# Use the filter facility to add custom headers to outbound messages.
add_custom_headers    unix  -       n       n       -       10      pipe
    flags=Rq user=filter null_sender=
    argv=/etc/postfix/add-custom-headers.sh -f ${sender} -- ${recipient}
  1. enable our new custom filter for email that arrives to Postfix via SMTP only. this is done with an -o argument line under smtp, like so:
smtp      inet  n       -       -       -       -       smtpd
  -o content_filter=add_custom_headers:dummy

reference: http://www.postfix.org/FILTER_README.html


Leave a comment

Please login or register to leave a comment!