CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
MAIL::IMAPClient slow or fails connect

 



simplyDENNIS
New User

Mar 12, 2011, 6:33 PM

Post #1 of 2 (2035 views)
MAIL::IMAPClient slow or fails connect Can't Post

Hi,
I'm trying to write an email mailbox manager, using MAIL::IMAPClient.

This is new undertaking for me, so could be newbie question tho I couldn't find anything in forum, but here's the deal.

Writing in linux (MEPIS 8.5). I have the routine running, using examples I found online - but the connection step is either slow (~30 secs) but successful, or just hangs, then after more time than I ever waited around to see, returns with:
login() Socket closed while reading data from server

Here's pertinent code:
==================================
#!/usr/bin/perl -w

use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
use Data::Dumper;
use IO::File;
use AppConfig qw/:argcount/;
use Time::Local;
.
.
.
.
# Connect to the IMAP server via SSL and get rid of server greeting message
my $socket = IO::Socket::SSL->new(
PeerAddr => $config->HOST,
PeerPort => $config->PORT,
)
or die "socket(): $@";
my $greeting = <$socket>;
my ($id, $answer) = split /\s+/, $greeting;
die "problems logging in: $greeting" if $answer ne 'OK';

# Build up a client attached to the SSL socket and login
###=======================================
### Note:
### Fails on the following step. Sometimes it works, but
### takes the 30 seconds. In this case, the program can
### successfully access the mailboxes
###
### Often, this step just hangs as described in intro above.
###=======================================
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => $config->USER,
Password => $config->PASSWORD,
Port => $config->PORT,
)
or die "new(): $@";
$client->State(Mail::IMAPClient::Connected());
$client->login() or die 'login(): ' . $client->LastError();

Any help or advice on better approach would be much appreciated.

Thanks,
DC


simplyDENNIS
New User

Mar 30, 2011, 6:32 AM

Post #2 of 2 (1946 views)
Re: [simplyDENNIS] MAIL::IMAPClient slow or fails connect [In reply to] Can't Post

I guess it would only be fair to reply myself, since I got past this point. Confusion was because version difference between CPAN doc and actual module on MEPIS Synaptic.

I don't think anyone cares, but my conscience will be clear - so
here is the code that worked on MAIL::IMAPClient v 3.08-2:
===========================================
#!/usr/bin/perl -d

use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;

#---------------------------------------
# Connect to the IMAP server via SSL
#---------------------------------------
my $socket = IO::Socket::SSL->new(
PeerAddr => 'imap.gmail.com',
PeerPort => 993,
)
or die "socket(): $@";

#-------------------------------------------------
# Build up a client attached to the SSL socket.
# Login is automatic as usual when we provide
# User and Password
#-------------------------------------------------
my $imap = Mail::IMAPClient->new(
Socket => $socket,
User => 'mailuser',
Password => 'mailpswd',
Debug => 'd'
)
or die "new(): $@";
DC

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives