【问题标题】:Connecting to Exchange without AutoDiscover?在没有自动发现的情况下连接到 Exchange?
【发布时间】:2020-03-05 01:11:35
【问题描述】:

我需要在我的工作场所设置一个自定义应用程序,以读取来自特定 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#的跟进

【问题讨论】:

    标签: c# outlook exchange-server autodiscovery


    【解决方案1】:

    如果您知道 EWS URL,您可以硬编码设置并删除您的 Autodiscover 代码,例如

    删除

    //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

    【讨论】:

      【解决方案2】:

      请记住,如果自动发现 XML 不可用,Outlook 2016 甚至都无法工作。您确实需要启用自动发现以确保 Outlook 正常工作。
      “安全设置不允许公开自动发现端点” - 我很好奇公开自动发现端点可能带来的安全隐患。

      【讨论】:

        猜你喜欢
        • 2017-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 2010-09-06
        • 2020-06-24
        • 2013-05-23
        相关资源
        最近更新 更多