出现类似“连接未成功。请稍后再试”的错误。与委托和模拟一起使用Microsoft.Exchange

时间:2018-08-31 11:20:15

标签: c# microsoft-exchange

  

在Useexchangeservice方法下面,该方法用于连接邮件服务器并从服务器获取邮件,但显示诸如“连接未成功。请稍后重试”的错误。

static void UseExchangeService()
    {
        string userEmailAddress = "xyz2@domain.com";
        string userPassword = "testnew@123";

        ExchangeService service = new 
        ExchangeService(ExchangeVersion.Exchange2010_SP2);

        #region Authentication
        service.UseDefaultCredentials = true;
        service.TraceEnabled = true;
        service.TraceFlags = TraceFlags.All;
        var folder = new FolderId(WellKnownFolderName.Calendar, new Mailbox(userEmailAddress));
       #endregion

        #region Endpoint management
        service.AutodiscoverUrl(userEmailAddress, 
        RedirectionUrlValidationCallback);
         #endregion

        EmailMessage email = new EmailMessage(service);
        email.ToRecipients.Add("Lalit.Sharma2@securemeters.com");
        email.Subject = "HelloWorld";
        email.Body = new MessageBody("Sent by using the EWS Managed API");

        email.Save(new FolderId(WellKnownFolderName.Drafts, "Lalit.Sharma2@securemeters.com"));
        email.Send();
         }

0 个答案:

没有答案