As a developer on a test server, it is essential for you to have full control over the emails being sent during application testing. Imagine that you are working on a project and constantly need to send test messages to a specific email address, allowing you to easily monitor email flows and perform automated tests.

To facilitate this, Postfix, a popular mail transfer agent, provides a convenient configuration option. By making some changes to the Postfix configuration files on your test server, you can ensure that all outgoing emails are delivered to a single recipient. This centralizes and simplifies the email flow, providing you with a better overview during the testing process.

Add the following to the end of the configuration file /etc/postfix/main.cf:

# Aangepaste toevoeging - alleen verzenden naar één e-mailadres.
recipient_canonical_classes = envelope_recipient
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical_map

In the file /etc/postfix/master.cf:

Find the line that looks something like this (without the "#" in front of it):

smtp unix - - n - - smtp

Immediately after that, add the following line:

-o smtp_header_checks=regexp:/etc/postfix/smtp_header_checks

Create a new file /etc/postfix/recipient_canonical_map and add the following:

# Voer het e-mailadres in waarnaar je alle e-mails wilt laten bezorgen.
# Bijvoorbeeld, mijn configuratie leest "/./ [email protected]"
/./ [email protected]

Also, create a new file /etc/postfix/smtp_header_checks and add the following:

# Dit zal de hele onderwerpregel nemen en er "[devmail]" voor plaatsen, als een andere manier om het te filteren.
/Subject:(.*)/ REPLACE Subject: [devmail] $1

After you have updated and created these configuration files, reload Postfix by running the following:

[~]# service postfix reload

If you have the mail command installed, send a test message to a nonexistent e-mail address:

[~]# echo 'test' | mail -s 'test email' [email protected]

To deny and disable the connection, edit the file /etc/postfix/main.cf:

vi /etc/postfix/main.cf

Comment out the following lines by placing "#" in front of them:

# content_filter = amavis:[127.0.0.1]:10024
# receive_override_options = no_address_mappings