Postfix menghapus queue berdasarkan alamat email

Script berikut ini sangat-sangat berguna sekali, karena di queue mail server ada 3000 email spam, kalo di delete satu-satu, bisa kriting jari gw, kalo di hapus semua email di queuenya, bisa kehapus juga dong pengiriman email ke client.

jadi mending bikin script dibawah ini, simpan di /etc/postfix
1. Buat file script-queue

#vim script-queue
#!/usr/bin/perl -w
#
# pfdel – deletes message containing specified address from
# Postfix queue. Matches either sender or recipient address.
#
# Usage: pfdel <email_address>
#

use strict;

# Change these paths if necessary.
my $LISTQ = “/usr/sbin/postqueue -p”;
my $POSTSUPER = “/usr/sbin/postsuper”;

my $email_addr = “”;
my $qid = “”;
my $euid = $>;

if ( @ARGV !=  1 ) {
die “Usage: pfdel <email_address>\n”;
} else {
$email_addr = $ARGV[0];
}

if ( $euid != 0 ) {
die “You must be root to delete queue files.\n”;
}

open(QUEUE, “$LISTQ |”) ||
die “Can’t get pipe to $LISTQ: $!\n”;

my $entry = <QUEUE>;    # skip single header line
$/ = “”;        # Rest of queue entries print on
# multiple lines.
while ( $entry = <QUEUE> ) {
if ( $entry =~ / $email_addr$/m ) {
($qid) = split(/\s+/, $entry, 2);
$qid =~ s/[\*\!]//;
next unless ($qid);

#
# Execute postsuper -d with the queue id.
# postsuper provides feedback when it deletes
# messages. Let its output go through.
#
if ( system($POSTSUPER, “-d”, $qid) != 0 ) {
# If postsuper has a problem, bail.
die “Error executing $POSTSUPER: error ” .
“code ” .  ($?/256) . “\n”;
}
}
}
close(QUEUE);

if (! $qid ) {
die “No messages with the address <$email_addr> ” .
“found in queue.\n”;
}

exit 0;

selanjunya

2. Simpan dan tutup script diatas tanpa melakukan perubahan di dalamnya.

3. Ubah hak akses biar bisa di eksekusi.
# chmod 777 script-queue

4. Lakukan eksekusi file tersebut
# ./script-queue freelotto@winners.org

selanjutnya tampak email akan di hapus berdasarkan email yg telah di definisikan diatas.

Terinspirasi oleh artikel ini

Semoga Bermanfaat

Adi Maulana

One response to “Postfix menghapus queue berdasarkan alamat email

  1. keamanan nya pake apa mas ya???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s