没有自动发现连接到Exchange?

时间:2017-06-04 22:34:48

标签: c# outlook exchange-server autodiscovery

我需要在我的工作场所设置自定义应用程序,从特定的Exchange Server邮箱中读取电子邮件主题行,并根据内容重定向它们。我编写了以下代码来测试连接性:

using System;
using Microsoft.Exchange.WebServices.Data;

namespace TestEmail
{
    class Program
    {
        static void Main(string[] args)
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.UseDefaultCredentials = true;
            //service.Credentials = new WebCredentials("user1@contoso.com", "password");

            service.TraceEnabled = true;
            service.TraceFlags = TraceFlags.All;

            service.AutodiscoverUrl("xxx@yyy.com", RedirectionUrlValidationCallback);

            EmailMessage email = new EmailMessage(service);

            email.ToRecipients.Add("xxx@yyy.com");

            email.Subject = "Test mail";
            email.Body = new MessageBody("Sending the test email");

            email.Send();
        }

        private static bool RedirectionUrlValidationCallback(string redirectionUrl)
        {
            // The default for the validation callback is to reject the URL.
            bool result = false;

            Uri redirectionUri = new Uri(redirectionUrl);

            // Validate the contents of the redirection URL. In this simple validation
            // callback, the redirection URL is considered valid if it is using HTTPS
            // to encrypt the authentication credentials. 
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        }
    }
  }
}

但工作场所安全设置不允许公开自动发现端点,我被告知此设置无法更改。

有没有其他方法可以连接到Exchange服务器,而不使用自动发现?

这是对我之前提问SSL/TLS error when connecting to Exchange from C#

的跟进

2 个答案:

答案 0 :(得分:0)

如果您了解EWS URL,则可以对设置进行硬编码并删除自动发现代码,例如

雷姆

// service.AutodiscoverUrl(" xxx@yyy.com",RedirectionUrlValidationCallback);

并使用

service.Url = new Uri(" https://computername.domain.contoso.com/EWS/Exchange.asmx");

另见https://msdn.microsoft.com/en-us/library/office/dn509511(v=exchg.150).aspx

答案 1 :(得分:0)

Keep in mind that Outlook 2016 will not even work if autodiscover XML is not available. You really need to enable autodiscover to make sure Outlook works.
"security settings disallow exposing autodiscovery endpoints" - I am curious what are the possible security implications of exposing autodiscover endpoints.

相关问题