Delete mails from pop3 server using perl script

My pop3 sever does not support dele *.* to delete all the messages. I have to delete one by one. Also i am accessing the pop3 server using telnet.
How to delete all mails from the pop3 server using perl script
i am using script  as below

#!/usr/local/bin/perl
$username='username';
$password='password';
$MAX_MESS=$1;
sleep 1;
print  "USER $username \r\n";
sleep 1;
print  "PASS $password \r\n";
sleep 1;
for ($j = 1 ; $j<10;$j++)
{
        print "dele $j";
        sleep 1;      
}
sleep 1;

print "Quit";

and executing it as

deletemails.pl | telnet <ip of pop3 server> 110

the output of the above script does not seem to redirect to the telnet client. Is there any other way?
riteshbawaskarAsked:
Who is Participating?
 
mjcoyneCommented:
#!/usr/bin/perl -w
use strict;
use Net::POP3;

my $username = 'username';
my $password = 'password';

my $server = Net::POP3->new('pop3host', Timeout => 60);

if ($server->login($username, $password) > 0) {
  my $msgs = $server->list;
  foreach my $msg (keys %$msgs) {
    $server->delete($msg);
  }
}

$server->quit;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.