May
Using ruby to delete mail in the Postfix mail queue
From time to time I find myself having to manually remove certain queued emails from the Postfix ‘mailq’, which sometimes can be hassle. For that matter I created a simple ruby script that lets me pass a regular expression argument for the emails to be matched against and therefore removing the matched emails from the Postfix mailq.
#!/usr/local/bin/ruby
#
# postdel.rb
# - Deletes emails queued in the Postfix mail queue
#
postqueue_bin = '/usr/sbin/postqueue'
postsuper_bin = '/usr/sbin/postsuper'
[postqueue_bin, postsuper_bin].each do |file|
unless File.executable?(file)
puts "The file #{file} doesn't exist or can't be executed."
exit
end
end
unless regex = ARGV[0]
puts "No email address provided (regex style, i.e. b\\(.*\\)@domain\\(.*\\)\\(com|net\\))"
exit
end
Read more...

