使用perl Mail :: IMAPClient连接到Microsoft Exchange IMAP4服务

时间:2016-09-26 14:42:52

标签: perl email ssl exchange-server imap

我正在尝试使用Mail :: IMAPClient连接到MS Exchange邮箱。 阅读INBOX中的消息,具体取决于内容格式,并将电子邮件发送到其他邮箱。

此代码段程序是仅使用IMAP连接然后断开连接的测试。该代码段无法连接,但我可以使用openssl进行连接。

!/usr/bin/perl

use strict;
use warnings;
use Mail::IMAPClient;

use lib "/usr/local/share/perl5";

my $IMAPserver  = "imapx.servers.net";
my $IMAPuser    = "emailUser";
my $IMAPpass    = "resUliame";
my $IMAPport    = 993;
print "Start\n";
# Attach a client using an SSL socket.
my $client = Mail::IMAPClient->new(
        Server          => $IMAPserver,
        Port            => $IMAPport,
        User            => $IMAPuser,
        Password        => $IMAPpass,
        Ssl             => 1,
        DEBUG           => 1
)
or die "new(): $@";
$client->State(Mail::IMAPClient::Connected);

# Close IMAP connections
$client->logout();
print "Done\n";

这是我得到的输出......

Start
Started at Mon Sep 26 10:28:16 2016
Using Mail::IMAPClient version 3.38 on perl 5.010001
Connecting with IO::Socket::SSL PeerAddr imapx.servers.net PeerPort 993 Proto tcp Timeout 600 Debug 1
ERROR: Unable to connect to imapx.servers.net:  at /usr/local/share/perl5/Mail/IMAPClient.pm line 370.
        Mail::IMAPClient::connect(Mail::IMAPClient=HASH(0x2064b98)) called at /usr/local/share/perl5/Mail/IMAPClient.pm line 313
        Mail::IMAPClient::new("Mail::IMAPClient", "Server", "imapx.servers.net", "Port", 993, "User", "emailUser", "Password", "resUliame", ...) called at ./testEmail.pl line 17
new(): Unable to connect to imapx.servers.net:  at ./testEmail.pl line 17

我可以用openssl连接,所以我知道服务器,端口,用户和用户passwd是对的。

# openssl s_client -connect imapx.servers.net:993 -crlf
CONNECTED(00000003)

* OK The Microsoft Exchange IMAP4 service is ready.
* LOGIN emailUser resUliame
* OK LOGIN completed.
* SELECT Inbox
* 28027 EXISTS
* 1 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UNSEEN 27544] Is the first unseen message
* OK [UIDVALIDITY 64268] UIDVALIDITY value
* OK [UIDNEXT 46567390] The next unique identifier value
* OK [READ-WRITE] SELECT completed. 

0 个答案:

没有答案