How to configure an SMTP Black Hole
Requirement: Build a web server that will receive email for a particular domain and discard it immediately (and silently).
I started with a canned Debian 9 system at OVH, but this should work with other and older Debian versions too.
Log in as root and make sure you’re all up to date:
apt-get update && apt-get upgrade
Set your hostname.
hostname fake echo "fake.fakemail.ca" > /etc/hostname
Install postfix
apt-get -y install postfix # Use the below as a guide for any configuration questions. You will probably only see the first two unless you do a 'dpkg-reconfigure postfix'. # on the "General type of mail configuration" screen, select "Internet Site" # on the "System mail name:" screen, accept the default of "localdomain". # on the "Root and postmaster mail recipient:" screen, leave the field blank. # on the "Other destinations to accept mail for (blank for none):" screen, remove your hostname from the list so that it reads "localhost, localhost.localdomain" # on the "Force synchronous updates on mail queue?" screen, select "No" because we don't care about the mail queue. Like at all. # on the "Local networks:" screen, accept the default "127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128" entry. # on the "Mailbox size limit (bytes):" screen, accept the default "0". # on the "Local address extension character:" screen, accept the default "+". # on the "Internet protocols to use:" screen, choose whatever applies to you. The default of "all" is probably OK.
Now we can configure aliases and postfix.
echo "devnull: /dev/null" > /etc/aliases newaliases
echo "@fakemail.ca devnull@localhost" > /etc/postfix/virtual postmap /etc/postfix/virtual
echo "@fakemail.ca /dev/null" > /etc/postfix/vmailbox postmap /etc/postfix/vmailbox
echo "virtual_mailbox_domains = fakemail.ca" >> /etc/postfix/main.cf echo "virtual_mailbox_base = /var/mail/vhosts" >> /etc/postfix/main.cf echo "virtual_mailbox_maps = hash:/etc/postfix/vmailbox" >> /etc/postfix/main.cf echo "virtual_minimum_uid = 100" >> /etc/postfix/main.cf echo "virtual_uid_maps = static:5000" >> /etc/postfix/main.cf echo "virtual_gid_maps = static:5000" >> /etc/postfix/main.cf echo "virtual_alias_maps = hash:/etc/postfix/virtual" >> /etc/postfix/main.cf postfix reload
Now watch the mail log and see everthing addressed to @fakemail.ca go to /dev/null
tail -f /var/log/mail.log
Example log entries for an email going to /dev/null:
Jun 27 15:09:09 fake postfix/smtpd[3449]: connect from mail-bl2nam02on0124.outbound.protection.outlook.com[104.47.38.124] Jun 27 15:09:09 fake postfix/smtpd[3449]: 355BB1F4F6: client=mail-bl2nam02on0124.outbound.protection.outlook.com[104.47.38.124] Jun 27 15:09:09 fake postfix/cleanup[3454]: 355BB1F4F6: message-id=<CO2PR16MB0028E0F1D3FAF4817E66B622B0DC0@CO2PR16MB0028.namprd16.prod.outlook.com> Jun 27 15:09:09 fake postfix/qmgr[3446]: 355BB1F4F6: from=<jeremy@jeremycole.com>, size=19947, nrcpt=1 (queue active) Jun 27 15:09:09 fake postfix/local[3455]: 355BB1F4F6: to=<devnull@localhost>, orig_to=<blah@fakemail.ca>, relay=local, delay=0.22, delays=0.22/0.01/0/0, dsn=2.0.0, status=sent (delivered to file: /dev/null) Jun 27 15:09:09 fake postfix/qmgr[3446]: 355BB1F4F6: removed Jun 27 15:09:09 fake postfix/smtpd[3449]: disconnect from mail-bl2nam02on0124.outbound.protection.outlook.com[104.47.38.124] ehlo=2 starttls=1 mail=1 rcpt=1 data=1 quit=1 commands=7