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
> 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
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,
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 **
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
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?
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.
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.
> 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
Any suggestions?
The host is "pop.gmail.com" NOT "pop.gmail.com:995"
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
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,