Mail::IMAPClient usage...

Y

Yogi

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',
'(e-mail address removed)',
'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
 
M

Martijn Lievaart

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',
'(e-mail address removed)',
'mypwd');

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

M4
 
Y

Yogi

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
 
Y

Yogi

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

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,
 
T

Ted Zlatanov

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
 
Y

Yogi

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 (e-mail address removed) as well as only 'myid' but all failed. I
am running this script from my windows machine with ActiveState
Perlv5.10.0.

Any suggestions?
 
J

J. Gleixner

Yogi said:
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.
 
M

Martijn Lievaart

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
 
T

Ted Zlatanov

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
 
Y

Yogi

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

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,
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top