Creating a discard/noreply email address with postfix and postfixadmin

On my mail server, I am using postfix/dovecot, with users in mysql managed by postfixadmin.

At one point I had something set up to create an email address where email would be accepted, but immediately discarded. This is sometimes called a “noreply” email address. This setup stopped working, most likely when I upgraded the system and put it in AWS.

So I went looking for a way to accomplish this. I came across a few different guides, none of which worked. Ultimately I worked out how to do it myself.

The first step is to create a transport mapping that maps a special email address to the discard transport. This involves putting a line in the file for postfix:

transport_maps = hash:/etc/postfix/transport

Then in the file referenced, add a line like the following, with a tab between the address and the “discard” keyword. discard:

For the transport email address, you’ll typically want to pick a hostname that is under your control, but not otherwise being used already for email service. Ideally it should be a hostname that’s defined in public DNS. The fully qualified hostname for the postfix server will probably work, and that is what I ended up using for my setup. If that doesn’t work, you could pick any unused hostname under in one of your domains. You could probably even make something up. The exact address that I used above with will even work, with some special database manipulation later on. The important thing is that the hostname part of the email address cannot be a domain that your mail server is set up to handle, and it should not be a domain that is valid on the Internet for real email addresses. The reason that the address I used in my example will work is that the domain is reserved by IANA.

After the transport file is changed, the “postmap” command must be run on that file to create the hashed version that postfix will actually consult. You’ll also need to restart postfix so the change to takes effect. A reload action might also work, but I have not tried it.

Once the transport map is created, hashed, and activated, you can go into postfixadmin and create aliases that point to the special email address. For instance, you could create a “noreply” alias on one of your domains, point it at or whatever address you used in the transport map, and then any email sent to that noreply address will be accepted and discarded.

Note:  If you pick a hostname for the transport
email address that's not in DNS, like the
example above, you can't create the alias in
the postfixadmin interface.  You'll need to
edit the alias table directly in the
database.  The postfixadmin interface will look
up any alias targets that are entered and will not
allow invalid ones.  One thing you could do is
enter a placeholder target in postfixadmin that's
valid in DNS and then edit the database directly.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.