【问题标题】:SSL/TLS error when connecting to Exchange from C#从 C# 连接到 Exchange 时出现 SSL/TLS 错误
【发布时间】:2017-06-02 19:10:04
【问题描述】:

我正在尝试测试将电子邮件发送到我自己的公司电子邮件 ID。我们将 Outlook 托管在 Exchange 服务器上。我使用了以下代码(出于隐私原因,将我的电子邮件 ID 替换为随机的):

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;
        }
    }
  }
}

当我运行此程序时,我收到一条错误消息,提示“AutodiscoverConfiguration failed: Web Exception(底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系)。

我不知道我的工作场所如何设置 Exchange Server 的安全性,因为它是由不同的团队处理的。

我该如何解决这个问题?

【问题讨论】:

    标签: c# outlook exchange-server


    【解决方案1】:

    如果您能在这里与当地的 Exchange 管理员合作,就好像自动发现有任何问题一样,我真的希望只有他们可以帮助解决问题。

    无论如何,根据我们目前掌握的较少信息,这里有一些可能的选择:

    1.) 这可能是 SSL 信任问题。确保用于您要连接的交换服务的根 CA 授权在您的应用程序/本地操作系统中受信任。根据您的本地配置,您需要在此处导入一些受信任的 SSL 根或信任自签名 ssl 证书。

    2.) 要检查自动发现问题,我们可以尝试通过Microsoft Remote Connectivity Test (Outlook Autodiscover) 进行远程检查。但根据 Exchange 服务器配置,可能会有内部和外部自动发现配置,并且验证外部并不意味着内部工作正常。如上所述:您需要与您的 Exchange 管理员合作。

    【讨论】:

    • 感谢您的回复!我试过你提到的微软远程连接测试,它仍然失败。因此,正如您所建议的,我想我需要从 Exchange 管理员那里获得帮助。
    • 将是最佳选择。如果需要,您可以finetune the Exchange AutoDiscovery process,但我不确定这是否适用于您自己创建的应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多