lig has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to learn how to receive and send mail with Perl from a web browser. Have been reading the Perl Cookbook to get a general feel for it by reading/learning about CGI and Net::POP3. Everything has been going pretty well until I actually tried to connect to the POP server.

I keep getting various error messages (that to me at least are not informative) returned. The error is occuring on the constructor for the POP3 object.

Particulars:
code is taken almost verbatim from the Perl Cookbook.

# use strict, warnings and diagnostics # retrieve the pop3 messages eval { print $page -> p(qw(We are going to retrieve the emails here since + you told us to do that.)), "\n"; # open a connection my $pop = Net::POP3->new(Host=>"pop.gmail.com:995") or die("Can't connect to the POP3 server: $! \n"); # log in defined($pop->apop('myaccount@gmail.com', 'mypass')) or die("Couldn't authenticate: $! \n"); # get the message list my $messageList = $pop->list() or die("Couldn't retreive message list: $! \n"); # for each of the messages foreach my $msgid (keys %$messageList) { my $message = $pop->get($msgid); if(defined($message)) { print $message; } else { warn ("Couldn't retreive message. msgId# $msgid"); next; } } }; if ($@) { print "Error occured $@ \n"; }

<Error message returned>
Error occured Can't connect to the POP3 server: Bad file descriptor
</Error message returned>

If I change the POP3 server to something like mail.domain.com, I get the error "Invalid Arguement" rather then Bad file descriptor. I have also tried it with and without the port number (or at least I think that is how you tell it which port to go to) with the same results.

I have read over the Net::POP3 docs on CPAN, reread the "Discussion" provided in Perl Cookbook and still can not figure out where I went wrong. Ideas, Hints, and Suggestions are always greatly appreciated.

life is a game... so have fun.

Replies are listed 'Best First'.
Re: Net::POP3 question
by neilh (Pilgrim) on Oct 06, 2005 at 06:50 UTC
Re: Net::POP3 question
by PodMaster (Abbot) on Oct 06, 2005 at 10:45 UTC
    I see a Debug option in the Net::POP3 documentation you could try.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Net::POP3 question
by zentara (Cardinal) on Oct 06, 2005 at 11:53 UTC
    I think the code from the Cookbook made need updating. The line

    my $pop = Net::POP3->new(Host=>"pop.gmail.com:995")

    dosn't look right to me, and the perldoc for Net::POP3 dosn't show that kind of usage.

    Try this

    #!/usr/bin/perl -w use Net::POP3; my $ServerName = "pop.gmail.com:995"; #my $pop3 = Net::POP3->new($ServerName, Debug =>1)||die("Couldn't log +on to server\n"); my $pop3 = Net::POP3->new($ServerName)||die("Couldn't log on to server +\n"); my $UserName = "zz"; my $Password = "ztest"; my $num_messages = $pop3->login($UserName, $Password)||die("Bad userna +me or password\n"); my $messages = $pop3->list(); print "******$messages $num_messages*******\n"; my %messages; my $msg_id; print "#################################################\n"; foreach $msg_id(keys %{$messages}) { # print "$msg_id\t$messages{$msg_id}\n"; my $messbody = $pop3->get($msg_id); print "################################################\n"; print "$msg_id\n"; print "@$messbody"; } print "####################################################\n"; $pop3->quit(); exit 0;

    I'm not really a human, but I play one on earth. flash japh
Re: Net::POP3 question
by lig (Acolyte) on Oct 07, 2005 at 00:00 UTC

    OK - taking your suggestions (and in zentara's case - code). I have gotten this:

    • zentara's original code: Get a "Bad File Descriptor" error
    • neilh's suggestion to change to a different mail account off of gmail (used a mail.domain.com account) in zentara's original code: Get a "Bad File Descriptor" error
    • As per PodMaster's suggestion - activate the debug option in zentara's original code - still using the alternate email address: Get a "Bad File Descriptor" error

    Any other ideas, suggestions or direction to take?

    life is a game... so have fun.