When in development, there will more than likely be a few instances where you will need to send email to clients or users. However, the last thing you want to do is mistakenly send an email to a client or user while in development.
With this in mind (and the fact that I use a development virtual machine which wouldn’t ever need to send emails to anyone but myself), I set up postfix to send all outgoing email to a single email address (mine) - regardless of who it is addressed to. Using the steps outlined below, you’ll be able to get your Postfix installation set up in a similar fashion.
/etc/postfix/main.cf, append the following to the end of the configuration file:
# Custom addition - only send to one email address, ever. recipient_canonical_classes = envelope_recipient recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map
# Find the line that looks similar to this (without the leading #): # smtp unix - - n - - smtp # Add this line immediately afterwards: -o smtp_header_checks=regexp:/etc/postfix/smtp_header_checks
/etc/postfix/recipient_canonical_map and place the following into it:
# Enter the email address to which you want all emails delivered. # For example, my configuration reads "/./ firstname.lastname@example.org" /./ email@example.com
/etc/postfix/smtp_header_checks and place the following into it:
# This will basically take the whole subject line, and place "[devmail] " in front of it - providing another way of filtering it. /Subject:(.*)/ REPLACE Subject: [devmail] $1
Once you have updated these configuration files, and created these files, give postfix a reload by executing the following:
[~]# service postfix reload
If you have the
[~]# echo 'test' | mail -s 'test email' firstname.lastname@example.org
If all your configuration has been updated and changed successfully, you should receive an email addressed to
email@example.com in your
firstname.lastname@example.org inbox. Now, no matter who an email is sent to, you can be certain it won’t be sent to any clients or other unintended recipients.