postfix blackhole

Singularity

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:
http://www.davidbehler.de/2011/07/dev-box-setting-up-a-mail-server-2/

Then followed this guide to configure the black hole http://notepad.patheticcockroach.com/2827/how-to-forward-an-e-mail-address-or-a-whole-domain-to-devnull-in-postfix/

also this guide: http://webpatrika.blogspot.com/2007/04/creating-no-replydomaincom-account-in.html

You will also need to set up, in /etc/postfix/main.cf:
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 = 10.200.147.0/24
inet_interfaces = all

Useful commands:


to view posts server is listening on:

#sudo netstat -plntu

to view a mailqueue

#postque -p
-or-
#mailq

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: http://tech.groups.yahoo.com/group/postfix-users/message/255133

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,}$}) {
++$c;
} 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`;
chomp($qdir);
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
——————————————————
#!/usr/bin/perl

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

@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”;
};
close(POSTSUPER);
——————————————————————-

Advertisements