http://www.perlmonks.org?node_id=1048685

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

I tried the following codes.But i did not get pop count.what mistake i did don't know.so please suggest solution

use warnings; use strict; use Mail::POP3Client; use IO::Socket::SSL; my $username ='vasanthgk91@gmail.com'; my $password ='password'; chomp($password); my $mailhost ='pop.gmail.com'; my $port ='995'; my $pop = new Mail::POP3Client( USER => $username, PASSWORD => $password, HOST => $mailhost, PORT => $port, USESSL => 'true', DEBUG => 0, ); if (($pop->Count()) < 1) { print "I Can't get pop count"; exit; }

Just I get "I Can't get pop count"

Replies are listed 'Best First'.
Re: how to read the Gmail Inbox using pop3client module?
by syphilis (Archbishop) on Aug 09, 2013 at 06:12 UTC
    Maybe there's no mail waiting there for you ? In that case $pop->Count() will be 0.
    You should check to see whether the connection succeeded. The documentation says:
    To test for a connection failure, you will need to check the number of + messages: -1 indicates a connection error.
    For USESSL to be successful, the documentation also says that you need to have IO::Socket::SSL installed. Do you have that module ?
    I would expect that you'd get an error if you don't have that module installed .... however, the documentation suggests that the absence of that module will simply cause the connection to silently fail.

    Cheers,
    Rob

      Yes I received pop->count() values "-1"..this is connection error i got it.But me IO::Socket::SSL installed properly.In previously yahoo Inbox i read through IO::Socket::SSL module.So IO::Socket::SSL not get problem.But how to solve the connection error in pop3client.This really don't know.

      thank you for your kind replay

        Consult with your network administrator, use a network analysis tool to see what goes over the wire and what connections are made. Maybe Mail::POP3Client has some hints on debugging?

        Also consider the more verbose approach, also listed in the documentation:

        ... $pop2 = new Mail::POP3Client( HOST => "pop3.otherdo.main" ); $pop2->User( "somebody" ); $pop2->Pass( "doublesecret" ); $pop2->Connect() >= 0 || die $pop2->Message(); ...

        That way, you get more information from ->Mesage() maybe.

        I strongly recommend you start reading the documentation of the module and follow the practices outlined there.

Re: how to read the Gmail Inbox using pop3client module?
by jakeease (Friar) on Aug 09, 2013 at 08:40 UTC

    I ran your code in the debugger and did get a proper count, but first I got this:

    main::(geemail.pl:15): my $port ='995'; DB<2> main::(geemail.pl:17): my $pop = new Mail::POP3Client( main::(geemail.pl:18): USER => $username, main::(geemail.pl:19): PASSWORD => $password, main::(geemail.pl:20): HOST => $mailhost, main::(geemail.pl:21): PORT => $port, main::(geemail.pl:22): USESSL => 'true', main::(geemail.pl:23): DEBUG => 0, main::(geemail.pl:24): ); DB<2> ******************************************************************* Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client is deprecated! Please set SSL_verify_mode to SSL_VERIFY_PEER together with SSL_ca_file|SSL_ca_path for verification. If you really don't want to verify the certificate and keep the connection open to Man-In-The-Middle attacks please set SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application. ******************************************************************* at C:/strawberry/perl/site/lib/Mail/POP3Client.pm line 376. at C:/strawberry/perl/vendor/lib/IO/Socket/SSL.pm line 312. IO::Socket::SSL::configure_SSL('IO::Socket::SSL=GLOB(0x3b909d0 +)', 'HASH(0x2adc148)') called at C:/strawberry/perl/vendor/lib/IO/Soc +ket/SSL.pm line 264 IO::Socket::SSL::configure('IO::Socket::SSL=GLOB(0x3b909d0)', +'HASH(0x2adc148)') called at C:/strawberry/perl/lib/IO/Socket.pm line + 49 IO::Socket::new('IO::Socket::SSL', 'Proto', 'tcp', 'PeerAddr', + 'pop.gmail.com', 'Type', 1, 'PeerPort', 995, ...) called at C:/straw +berry/perl/vendor/lib /IO/Socket/IP.pm line 331 IO::Socket::IP::new('IO::Socket::SSL', 'PeerAddr', 'pop.gmail. +com', 'PeerPort', 995, 'Proto', 'tcp', 'Type', 1, ...) called at C:/s +trawberry/perl/site/l ib/Mail/POP3Client.pm line 376 Mail::POP3Client::Connect('Mail::POP3Client=HASH(0x3b8f088)') +called at C:/strawberry/perl/site/lib/Mail/POP3Client.pm line 79

    So, for me it worked at the next step

    DB<2> l 26==> if (($pop->Count()) < 1) 27 { 28: print "I Can't get pop count"; 29: exit; 30 } 31 DB<2> p $pop->Count() 320 DB<3>
    but definitely hints at potential snags in the network/security configuration arena.

      IMAP via I got the output

      https://accounts.google.com/DisplayUnlockCaptcha

      on a browser.

      I follow the link and unlock the captcha after i read the gmail inbox

      Thank you

Re: how to read the Gmail Inbox using pop3client module?
by hulfordp (Initiate) on Jun 24, 2014 at 11:59 UTC
    I had very similar code working in an old version of perl. I upgraded and then only received connection failure. Connection failure was silent.

    I moved back to old version of perl and connections worked fine (also made sure I used the same packages and same code). The perl version that worked on my windows 7 64 bit machine was 5.14.2 build 1402. The version that did not work was 5.16.3 build 1604.

    Best Paul