Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在没有自动发现的情况下连接到Exchange?_C#_Outlook_Exchange Server_Autodiscovery - Fatal编程技术网

C# 在没有自动发现的情况下连接到Exchange?

C# 在没有自动发现的情况下连接到Exchange?,c#,outlook,exchange-server,autodiscovery,C#,Outlook,Exchange Server,Autodiscovery,我需要在我的工作场所设置自定义应用程序,从特定Exchange Server邮箱读取电子邮件主题行,并根据内容重定向它们。我编写了以下代码来测试连接性: using System; using Microsoft.Exchange.WebServices.Data; namespace TestEmail { class Program { static void Main(string[] args) { Exchang

我需要在我的工作场所设置自定义应用程序,从特定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;
        }
    }
  }
}
但是workplace安全设置不允许公开自动发现端点,我被告知此设置无法更改

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


这是我上一个问题的后续问题

如果你知道你的EWS URL,你只需硬编码设置,并摆脱你的
自动发现
代码,例如

除去

//service.AutodiscoverUrl("xxx@yyy.com", RedirectionUrlValidationCallback);
和使用:

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

另请参见

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