Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mail::IMAPClient usage...

6 views
Skip to first unread message

Yogi

unread,
Jul 22, 2008, 12:47:41 AM7/22/08
to
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',
'my...@gmail.com',
'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:
$@";

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

Martijn Lievaart

unread,
Jul 22, 2008, 2:41:15 AM7/22/08
to
On Mon, 21 Jul 2008 21:47:41 -0700, Yogi wrote:

> 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',
> 'my...@gmail.com',
> 'mypwd');

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

M4

Yogi

unread,
Jul 22, 2008, 4:04:30 AM7/22/08
to
On Jul 22, 11:41 am, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
> On Mon, 21 Jul 2008 21:47:41 -0700, Yogi wrote:
> > 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',
> >                                 'm...@gmail.com',

> >                                 'mypwd');
>
> Ahum, IMAP is not pop3, and Mail::IMAPClient does only IMAP. I think you
> should look for a pop3 client library.
>
> M4

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

unread,
Jul 22, 2008, 5:29:50 AM7/22/08
to

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 $@");

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,

Rick Sanders

unread,
Jul 22, 2008, 9:05:22 AM7/22/08
to
> 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 $@");

Your host argument is incorrect so you're not actually getting a
connection to the gmail POP server. Use the following instead:

HOST => "pop.gmail.com:995",

It's not necessary to supply the port number either.

-Rick
** Posted from http://www.teranews.com **

Ted Zlatanov

unread,
Jul 22, 2008, 9:22:49 AM7/22/08
to
On Tue, 22 Jul 2008 08:41:15 +0200 Martijn Lievaart <m...@rtij.nl.invlalid> wrote:

ML> On Mon, 21 Jul 2008 21:47:41 -0700, Yogi wrote:
>> ($MAILSERVER,$USER,$PW,$num) = ('pop.gmail.com:995/pop3/ssl',
>> 'my...@gmail.com',
>> 'mypwd');

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

Yogi

unread,
Jul 22, 2008, 9:55:08 AM7/22/08
to
On Jul 22, 6:22 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Tue, 22 Jul 2008 08:41:15 +0200 Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>
> ML> On Mon, 21 Jul 2008 21:47:41 -0700, Yogi wrote:
>
> >> ($MAILSERVER,$USER,$PW,$num) = ('pop.gmail.com:995/pop3/ssl',
> >> 'm...@gmail.com',

> >> 'mypwd');
>
> 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

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 $@");

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

Any suggestions?


Rick Sanders

unread,
Jul 22, 2008, 10:28:28 AM7/22/08
to
> I tried all suggested changes but no success so far.
> Any suggestions?

Please post the output from your program with DEBUG enabled. That
should point out the problem. You should see something like this:

POP3 <- +OK Gpop ready for requests from <IP> 6pf7997068ywp.0
at ./popClient.pl line 5
POP3 -> CAPA
at ./popClient.pl line 5
POP3 <- +OK Capability list follows

[ snipped ]

POP3 -> USER <your username>
at ./popClient.pl line 5
POP3 <- +OK send PASS
at ./popClient.pl line 5
POP3 -> PASS <your password>
at ./popClient.pl line 5
POP3 <- +OK Welcome.
at ./popClient.pl line 5
POP3 -> STAT
at ./popClient.pl line 5
POP3 <- +OK 189 5021055
etc

"189" is the mail count in my gmail account.

Some other thoughts. Try changing your password to something bogus and
see if the results change. If not, you may not be making an SSL
connection to gmail, eg your username/password may be wrong.

Is the IO::Socket::SSL module installed on your system? Does it have an
SSL library installed?

If you have an account on another server try to connect to it, both with
and without SSL.

J. Gleixner

unread,
Jul 22, 2008, 11:58:37 AM7/22/08
to
Yogi wrote:
> On Jul 22, 6:22 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>> On Tue, 22 Jul 2008 08:41:15 +0200 Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>>
>> ML> On Mon, 21 Jul 2008 21:47:41 -0700, Yogi wrote:
>>
>>>> ($MAILSERVER,$USER,$PW,$num) = ('pop.gmail.com:995/pop3/ssl',
>>>> 'm...@gmail.com',
>>>> 'mypwd');
>> 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
>
> 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 $@");
>

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.

Martijn Lievaart

unread,
Jul 22, 2008, 1:36:43 PM7/22/08
to
On Tue, 22 Jul 2008 02:29:50 -0700, Yogi wrote:

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

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

Thrill5

unread,
Jul 22, 2008, 8:54:17 PM7/22/08
to

"Yogi" <yogeshk...@gmail.com> wrote in message
news:49dfef1f-4b74-406f...@m36g2000hse.googlegroups.com...

Any suggestions?


The host is "pop.gmail.com" NOT "pop.gmail.com:995"


Ted Zlatanov

unread,
Jul 23, 2008, 10:52:22 AM7/23/08
to
On Tue, 22 Jul 2008 06:55:08 -0700 (PDT) Yogi <yogeshk...@gmail.com> wrote:

Y> On Jul 22, 6:22 pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>> ...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.

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 $@");

My suggestion is to:

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

Ted

Yogi

unread,
Jul 24, 2008, 1:06:52 AM7/24/08
to
On Jul 23, 7:52 pm, Ted Zlatanov <t...@lifelogs.com> wrote:

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,

0 new messages