Perl Mass Deleting Email Script.

© copyright 12.May.2007 by Paul Bradley filed under Perl


[Ad] need a break from coding?

Hoseasons Villas

Why would you want to mass delete emails?

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.

The Perl Script

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!";

 

 


If you have found this article helpful or useful please consider linking to it, emailing it to friends, or share it with others using social sites like del.icio.us, Stumble Upon or Twitter.

Paul Bradley

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.

Other Popular Articles

Categories & Topics

Home · Apache · JavaScript · Perl · PDF · PHP · MySQL · MSSQL · TAR · Ubuntu Linux · Video · Visual Basic

Browse the complete article history, and if you like what you see; consider subscribing to the rss feed.