next up previous contents
Next: Usenet News: the News::NNTPClient Up: Perl on the Web Previous: Web Clients: the LWP   Contents

Accessing Email: the Net::POP3 module

   use Net::POP3;
   use Term::ReadKey;
   
   $pop = Net::POP3->new();
   
   print "Username? ";
   chomp($user = <STDIN>);
   
   print "Password? ";
   ReadMode('noecho');
   chomp($pass = <STDIN>);
   ReadMode(0);
   
   $pop->login($user,$pass) || die ("Couldn't login");
   $msgs = $pop->list();
   $nmsg = scalar keys(%$msgs);
   
   print "\nYou have $nmsg messages\n";
   
   foreach $id (keys %$msgs){
        $themessage = $pop->get($id);            
        print "No message\n" if not $themessage;
        print grep(/^\s*(Subject|From):/,@$themessage);
        print "Read? ";
        if(scalar<STDIN> =~ /^y/i){
               print "the message=@$themessage";
        }
   }


Phil Spector 2002-10-18