1

下面的 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();
         }
4

0 回答 0