Reputation: 83
I am trying to connect to an Outlook email server via IMAP and the error I am getting is curious. Here is a sample of my code:
use Mail::IMAPClient;
my $imap = Mail::IMAPClient->new;
$host='outlook.office365.com';
$username='.....';
$password='.....';
$folder='INBOX';
$imap=Mail::IMAPClient->new(
Server => $host,
User => $username,
Password => $password,
Port => 993,
Ssl => 1,
Clear=> 5,
Folder => $folder,
Uid => 0,
) or die "Cannot connect to $host as $username: $@";
When I run this, the output line looks like this:
Cannot connect to outlook.office365.com as [...]: Socket closed while reading data from server.
More specifically, Socket closed while reading data from server is what is confusing me.
I specify port 993, so is the only remaining possible issue that there's a firewall in place that is preventing this? I have emailed my school's (this is a school email account) tech department (quite some time ago) and they have yet to get back, but hopefully I will hear from them soon.
I get an even stranger error when I remove the line specifying the port, I am including it only in the hopes it is somehow relevant or helpful:
Cannot connect to outlook.office365.com as [...]: Error sending '1 Login "[email protected]" {15} [password is shown here, along with a newline character I can't seem to force here] ' to IMAP: Bad file descriptor at ./test.pl line 10.
Upvotes: 1
Views: 3072
Reputation: 123461
Please check directly with openssl:
openssl s_client -connect outlook.office365.com:993
This should give you a connection and at the end the welcome message from the IMAP server:
* OK The Microsoft Exchange IMAP4 service is ready. ....
If this does not work the connection is blocked by firewall or so. If this works try connecting with IO::Socket::SSL, which is the module Mail::IMAPClient uses for SSL connections:
perl -MIO::Socket::SSL -e 'print IO::Socket::SSL->new(q[outlook.office365.com:993])->getline.""'
This should also give you the welcome message. If it does not there might be problems with certificate checking or so. In this case please post the versions of modules you use and the OS, e.g.
perl -e 'print "version=$^V, os=$^O\n"'
perl -MIO::Socket::SSL -e 'print IO::Socket::SSL->VERSION,"\n"'
perl -MMail::IMAPCient -e 'print Mail::IMAPClient->VERSION,"\n"'
But, if IO::Socket::SSL gets a successful connection please add the Debug => 1
option to Mail::IMAPClient->new
and add the output to your question.
Upvotes: 1