This post will show a simple perl tool to manage (delete) one or more message in Postfix mail queue.
The main script to use is delete-mailq.pl
Create a file called delete-mailq.pl in /usr/local/bin with the the following content :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
< /pre > #!/usr/bin/perl -w # Postfix mailq cleanup utility $REGEXP = shift || die "no email-adress given (regexp-style, test.*@example.com)!" ; @data = qx< /usr/sbin/postqueue -p>; for (@data) { if (/^(w+)*?s/) { $queue_id = $1; } if ($queue_id) { if (/$REGEXP /i ) { $Q{$queue_id} = 1; $queue_id = "" ; } } } open (POSTSUPER, "|postsuper -d -" ) || die "couldn't open postsuper" ; foreach (keys %Q) { print POSTSUPER "$_n" ; }; close(POSTSUPER); <pre> |
Assign it correct ownership and permission with the following commands :
1
2
3
4
|
< /pre > chown root:root /usr/local/bin/delete-mailq .pl chmod 700 /usr/local/bin/delete-mailq .pl <pre> |
You should run the file directly passing the variables directly on comand line, or you should (and I prefer) create another file in /usr/local/bin called clean-mailq.sh with the following content :
1
2
3
4
5
6
7
8
9
10
11
12
13
|
< /pre > #!/bin/sh if [ -z $1 ] then echo "Insert the E-Mail address or a string to find it in mailqueue and delete it" read STRING else STRING=$1 fi /usr/local/bin/delete_mailq .pl $STRING <pre> |
Assign it correct ownership and permission with the following commands :
1
2
3
4
|
< /pre > chown root:root /usr/local/bin/clean-mailq .sh chmod 700 /usr/local/bin/clean-mailq .sh <pre> |
At this time, you should execute /usr/local/bin called clean-mailq.sh as root and pass the value to find and to delete from mail queue.
Hope this help
Bye
Riccardo
Recent Comments