title: Connection error using Net::IMAPClient in Perl
body: <p>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:</p>
  
  <pre><code>use Mail::IMAPClient;
  
  my $imap = Mail::IMAPClient-&gt;new;
  $host='outlook.office365.com';
  $username='.....';
  $password='.....';
  $folder='INBOX';
  $imap=Mail::IMAPClient-&gt;new(
                  Server =&gt; $host,
                  User =&gt; $username,
                  Password =&gt; $password,
                  Port =&gt; 993,
                  Ssl =&gt; 1,
                  Clear=&gt; 5,
                  Folder =&gt; $folder,
                  Uid =&gt; 0,
  )       or die "Cannot connect to $host as $username: $@";
  </code></pre>
  
  <p>When I run this, the output line looks like this:</p>
  
  <p>Cannot connect to outlook.office365.com as [...]: Socket closed while reading data from server.</p>
  
  <p>More specifically, <strong>Socket closed while reading data from server</strong> is what is confusing me.</p>
  
  <p>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. </p>
  
  <p>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:</p>
  
  <p>Cannot connect to outlook.office365.com as [...]: Error sending '1 Login "baldassaren@wit.edu" {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.</p>