远程主机Imap客户端强制关闭现有连接

时间:2015-09-05 13:09:03

标签: c# model-view-controller

我正在尝试在Outlook中连接我的帐户以下收件箱中的邮件,但有时会收到错误"现有连接被远程主机Imap客户端强行关闭"。我不知道为什么有时会出现这个错误。请帮忙 !

        var client = new ImapClient();

        client.Port = 993;
        client.SslProtocol = SslProtocols.Default;
        client.Host = "imap-mail.outlook.com";
        client.ValidateServerCertificate = true;
        client.UseSsl = true;

        if (client.Connect())
        {
            if (client.Login(Resources.BaseAdmin.EmailClient, Resources.BaseAdmin.EmailClientPass))
            {
                client.Folders.Inbox.Messages.Download();

                MessageCollection messages = client.Folders.Inbox.Messages;
                var message = messages.Where(x => x.UId == id).First();

                message.Seen = true;

                message.Body.Download();
                viewModel.Content = message.Body.Html;
                viewModel.DateOfSend = message.Date.ToString();
                viewModel.From = message.From.Address;
                viewModel.Subject = message.Subject;
                viewModel.To = message.To.First().Address;
                viewModel.UId = id;

                viewModel.Request.ProviderEmail = message.From.Address;
            }
        }
        else
        {
            ModelState.AddModelError("", "Connection Failed. Please refresh !");
        }
        client.Disconnect();

0 个答案:

没有答案