Wednesday, December 23, 2009

Clenup Email Queue on Postfix Mail Server based on From or Recepent (RCPT) address


Removing Queued Email from Postfix queue based on From or Recipient (rcpt) address.


We, administrators of Postfix mail server sometime need to remove email based on From address or Recipient (RCPT) address and we know how much time can kill when any virus / spam email / warm etc relay email on SMTP servers. I found a easy script to remove all targeted email from queue. Here is that script, writen on perl:



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

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 \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 = ; # skip single header line
$/ = ""; # Rest of queue entries print on
# multiple lines.
while ( $entry = ) {
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;

### End of Script ####

I don't know the name of the writer of script above. But found in URL:

http://www.ustrem.org/en/articles/postfix-queue-delete-en/

Use it and hope it will save your times. Good Day.

0 comments:

Other Posts

Labels / Category

3G (4) Adsense (2) AKTEL (2) Amateur Radio (3) APNIC (5) Bajaj Discovery (1) Bajaj Pulsar (1) Bangla News (5) Bangladesh (29) Bangladesh Computer Market (1) Bangladesh Cricket (2) Bangladesh earthquake (3) Bangladesh Educational Board (1) Bangladesh Energy (4) Bangladesh ICT (15) Bangladesh Internet Service (14) Bangladeshi Credit Card (3) Bangladeshi News Site (3) Bank in Bangladesh (7) Bank of Bangladesh (10) Banking in Bangladesh (10) BGMEA Bulding (1) Big File Download (3) blackhat (1) BLOG (6) Bogon (3) bot (2) BTCL (3) BTRC (13) BTTB Internet (10) BTTB Submarine Cable (9) Byke Hijack (1) Cacti (1) Call Block (1) Carbon Credit (1) CentOs (2) CentOs Bangladesh (2) Charity (2) Chrome (2) Computer Booting (1) Credit Card (10) Credit Card in Bangladesh (8) Crime (3) CyberCrime (11) Cyclon (1) DDoS (8) Dengue (1) Denmark (1) Dhaka earthquake (5) DNS (3) DNSSEC (2) Domain (9) DoS (4) dot bd domain (3) Dot CO.CC (2) Download (4) Drive not opening on click (1) DV Lottery 2010 (2) E-Learning (1) earthquake (5) EARTHQUAKE BANGLADESH (2) EARTHQUAKE DHAKA (2) earthquake in Bangladesh (5) earthquake in Dhaka (5) Email (7) Email Full Header (3) Email Sender Identify (4) Entertainment (2) Fake Email Sender (5) Firefox (8) FTP (1) Funny (4) GMail (4) Google (18) GPRS Settings (1) GrameenPhone (1) HAM (4) Health (3) Hobby (1) IGW (3) IIG (3) India (1) Indian ICT (1) Indian IT (1) Internet (19) Internet Mail (1) Internet Security (9) iPhone (3) iPhone Bangla (2) iPhone Bangladesh (2) iPhone in Dhaka (2) iPod (1) IPv4 Allocation (8) ipv6 (10) islam (4) ISOC (3) Linux Articles (6) Metal News (1) Microsoft (4) Microsoft buy Yahoo (1) Mirror Server (1) Mobile Phone (3) Mobile Phone Internet (1) Mobile Phone News (3) Mobile Phone Operator (6) Mobile Phone User (3) Mozilla (8) Mozilla Firefox (8) Myself (1) Mystery (1) Netcraft (4) Network Monitoring (4) neverBot (2) News Site (1) Nokia (3) Oil Price (2) Online Security (7) Paypal in Bangladesh (6) Personal View (1) Phishing (2) Pigeons (1) Postfix (7) PSTN (2) RANGS Bulding (1) Relay Host (2) robot.txt (1) robots.txt (2) Scour (2) Scour.com (2) Second submarine cable (3) Sendmail (4) Share Market (4) Smart Relay (3) SSC Result 2008 (1) Stock Market (3) Technology (1) Ubuntu (4) UCB (5) UCBL (5) URL Redirect (2) Virus (3) Virus Infected Windows (3) Virus Information (3) Warid (2) Web Spider (3) Webhosting (6) Wimax (4) Windows (1) Windows Problems (1) Wireless Internet in Bangladesh (5) Yahoo (4) Yahoo Sold (1)

Share it