© copyright 12.May.2007 by Paul Bradley filed under Perl
There could be lots of reasons for wanting to mass delete a whole load of emails from a POP3 server account. I have a reseller hosting account with Web Fusion that has a catch all master email account, which can't be configured at the server end to delete all incoming mail by default. As I never connected to this POP3 account with my email client, I just left it there accumulating emails.
After a couple of years though, the account had received several thousand emails (all spam), which was starting to eat into my disk space allowance; so I needed a quick way to mass delete all the emails from the account.
Below is the small perl script I wrote, which uses the POP3Client module to connect to a mail server, and then loop through all the messages, issuing a delete command.
You will need to substitute your username and password details, and enter your mail servers host name, for the script to work.
use strict;
use Mail::POP3Client;
my $pop = new Mail::POP3Client(
USER => "your_pop3_username",
PASSWORD => "your_pop3_password",
HOST => "your_mail.server.com");
for(my $i = 1; $i <= $pop->Count(); $i++ ) {
print "deleting mail message # $i
";
$pop->Delete($i);
}
$pop->Close();
print "Done!";
About the Author
Paul Bradley is a VB.NET software developer living and working in Cumbria. He provides PHP & MySQL bespoke development services via his software development company, Carlisle Software Limited.
He has over 20 years programming experience.