Perl Mass Deleting Email Script

published : 12.May.2007

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 \n";
    $pop->Delete($i);
}

$pop->Close();
print "Done!";

What Next?

Bookmark this article at :-

 

 

About Author:
I'm a father, husband, and a software developer who works for the NHS. more »

Sections :
« Articles
« Contact


 

TIFF Splitter - A windows utility to split multipage TIFF files into single pages.