#!/usr/bin/perl -w use strict; use Mail::POP3Client; my $user = 'blahblahblah'; my $pass = 'blahblahblah'; my $pop = new Mail::POP3Client( USER => $user, PASSWORD => $pass, HOST => "pop.gmail.com", PORT => 995, USESSL => 'true', ); my $count = $pop->Count(); if ($count < 0) { print $pop->Message(); } elsif ($count == 0) { print "no messages\n"; } else { for my $i (1 .. $count) { open(STDOUT, ">my_txt_output.txt"); my $fh = new IO::Handle(); $fh->fdopen( fileno( STDOUT ), "w" ); $pop->HeadAndBodyToFile( $fh, $i ); close STDOUT; } } $pop->Close();