【发布时间】: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