postfix blackhole


Set up a black hole server in postfix. The server will send all emails to the catch all email. This catch all email has also been aliased to /dev/null

followed this guide to set up the catchall:

Then followed this guide to configure the black hole

also this guide:

You will also need to set up, in /etc/postfix/
virtual_alias_maps = hash:/etc/postfix/virtual
And remember to run postmap /etc/postfix/virtual, once you entered the aliases on the file.

be sure to add this to the mynetworks line:
mynetworks =
inet_interfaces = all

Useful commands:

to view posts server is listening on:

#sudo netstat -plntu

to view a mailqueue

#postque -p

To remove mail:

#postsuper -d ALL

or to remove all defered
# postsuper -d ALL deferred

Perl script to show email queue
#!/usr/bin/env perl

# postfix queue/s size
# author:
# source:

use strict;
use warnings;
use Symbol;
sub count {
my ($dir) = @_;
my $dh = gensym();
my $c = 0;
opendir($dh, $dir) or die “$0: opendir: $dir: $!\n”;
while (my $f = readdir($dh)) {
if ($f =~ m{^[A-F0-9]{5,}$}) {
} elsif ($f =~ m{^[A-F0-9]$}) {
$c += count(“$dir/$f”);
closedir($dh) or die “closedir: $dir: $!\n”;
return $c;
my $qdir = `postconf -h queue_directory`;
chdir($qdir) or die “$0: chdir: $qdir: $!\n”;
printf “Incoming: %d\n”, count(“incoming”);
printf “Active: %d\n”, count(“active”);
printf “Deferred: %d\n”, count(“deferred”);
printf “Bounced: %d\n”, count(“bounce”);
printf “Hold: %d\n”, count(“hold”);
printf “Corrupt: %d\n”, count(“corrupt”);

perl script to delete from queue that matches regex

$REGEXP = shift || die “no email-adress given (regexp-style, e.g. bl.*\!”;

@data = qx;
for (@data) {
if (/^(\w+)(\*|\!)?\s/) {
$queue_id = $1;
if($queue_id) {
if (/$REGEXP/i) {
$Q{$queue_id} = 1;
$queue_id = “”;

#open(POSTSUPER,”|cat”) || die “couldn’t open postsuper” ;
open(POSTSUPER,”|postsuper -d -“) || die “couldn’t open postsuper” ;

foreach (keys %Q) {
print POSTSUPER “$_\n”;