Mail::IMAPClient usage...

Discussion in 'Perl Misc' started by Yogi, Jul 22, 2008.

  1. Yogi

    Yogi Guest

    Hi All,
    I am trying to login to my gmail id using MAIL::IMAPClient modules
    available in CPAN. I took sample code available (for my POC) but it
    is not working. Here is the snippet for your reference:


    use strict;
    use warnings;
    # Use CPAN modules to handle mails
    use Mail::IMAPClient;

    my ($MAILSERVER,$USER,$PW,$num) = ();

    ($MAILSERVER,$USER,$PW,$num) = ('pop.gmail.com:995/pop3/ssl',
    '',
    'mypwd');

    my $imap = Mail::IMAPClient->new;

    $imap = Mail::IMAPClient->new(
    Server => $MAILSERVER,
    User => $USER,
    Password=> $PW,
    Clear => 5
    ) or die "Cannot connect to $MAILSERVER as $USER:
    [email protected]";

    Getting Error as:
    Cannot connect to pop.gmail.com:995/pop3 as myid: Unable to connect to
    pop.gmail.com:995/pop3: IO::Socket::INET: Bad service '143' at test.pl
    line 15.

    Do I need to set any environment variable before using this module?
    Any SSL socket need to be made?

    This is the first time I am using this module and hence I am not very
    sure if this usage is correct or not.

    Regards
     
    Yogi, Jul 22, 2008
    #1
    1. Advertisements

  2. Ahum, IMAP is not pop3, and Mail::IMAPClient does only IMAP. I think you
    should look for a pop3 client library.

    M4
     
    Martijn Lievaart, Jul 22, 2008
    #2
    1. Advertisements

  3. Yogi

    Yogi Guest

    Thanks Martijn. As you suggested, Mail::pOP3Client is available which
    I might use. So, in run time if I have to go to IMAP, i will have to
    use IMAPClient otherwise POP3Client :(.
    Will try using POP3 library for now.

    Regards,
    Y
     
    Yogi, Jul 22, 2008
    #3
  4. Yogi

    Yogi Guest

    Well, I tried using POP3Client as well but no success.


    use strict;
    use Mail::pOP3Client;
    my $pop = new Mail::pOP3Client( USER => 'myid',
    PASSWORD => 'mypwd',
    HOST => "pop.gmail.com:995/pop3/
    ssl",
    USESSL => 1,
    PORT => 995,
    DEBUG => 1
    ) || die("Error here [email protected]");

    my $msgCount = $pop->Count();
    print "msgCount = $msgCount \n";

    for( my $i = 1; $i <= $pop->Count(); $i++ ) {
    foreach( $pop->Head( $i ) ) {
    /^(From|Subject):\s+/i && print $_, "\n";
    }
    }
    $pop->Close();

    this code is not failing while trying to connect but giving msgCount =
    -1. Am I missing anything here again?

    Regards,
     
    Yogi, Jul 22, 2008
    #4
  5. Yogi

    Ted Zlatanov Guest

    ML> Ahum, IMAP is not pop3, and Mail::IMAPClient does only IMAP. I think you
    ML> should look for a pop3 client library.

    ....he could also use GMail's IMAP services.

    GMail IMAP, incidentally, implements a very basic subset of IMAP, but
    it's probably enough for the OP.

    Ted
     
    Ted Zlatanov, Jul 22, 2008
    #5
  6. Yogi

    Yogi Guest

    Hi Ted n Rick,
    Thanks for your response on this. But even this is not working.

    my $pop = new Mail::pOP3Client( USER => 'myid',
    PASSWORD => 'mypwd',
    HOST => "pop.gmail.com:995",
    USESSL => 1,
    DEBUG => 1
    ) || die("Error here [email protected]");

    I tried all suggested changes but no success so far. For userid, I
    tried giving as well as only 'myid' but all failed. I
    am running this script from my windows machine with ActiveState
    Perlv5.10.0.

    Any suggestions?
     
    Yogi, Jul 22, 2008
    #6
  7. Yogi

    J. Gleixner Guest

    That's probably not how you would display the actual error.

    Form the perldoc:

    new returns a valid Mail::pOP3Client object in all cases. To test for a
    connection failure, you will need to check the number of messages: -1
    indicates a connection error. This will likely change sometime in the
    future to return undef on an error, setting $! as a side effect. This
    change will not happen in any 2.x version.

    Follow the documentation and use the Message method.
     
    J. Gleixner, Jul 22, 2008
    #7
  8. Yes, you missed to read the documentation.

    ] new returns a valid Mail::pOP3Client object in all cases. To test for a
    ] connection failure, you will need to check the number of messages: -1
    ] indicates a connection error. This will likely change sometime in the
    ] future to return undef on an error, setting $! as a side effect. This
    ] change will not happen in any 2.x version.

    I guess you should give the servername as "pop.gmail.com", not
    "pop.gmail.com:995/pop3/ssl".

    HTH,
    M4
     
    Martijn Lievaart, Jul 22, 2008
    #8
  9. Yogi

    Ted Zlatanov Guest

    Y> Hi Ted n Rick,
    Y> Thanks for your response on this. But even this is not working.

    Y> my $pop = new Mail::pOP3Client( USER => 'myid',
    Y> PASSWORD => 'mypwd',
    Y> HOST => "pop.gmail.com:995",
    Y> USESSL => 1,
    Y> DEBUG => 1
    Y> ) || die("Error here [email protected]");

    My suggestion is to:

    1) enable IMAP on GMail (it's in the account settings, including server name)
    2) use Mail::IMAPClient

    Ted
     
    Ted Zlatanov, Jul 23, 2008
    #9
  10. Yogi

    Yogi Guest

    Hi Ted,
    I did enable IMAP setting in my Gmail but was facing same issue. I
    found that there are some issues with SSL installation. I was tied up
    with some other work last night and hence could not work on this.
    will resolve SSL issues and will try again.
    Really, this is the best place to learn things. Thank you all.

    Regards,
     
    Yogi, Jul 24, 2008
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.