从Web页面运行时,Exchange Web服务返回401未授权

时间:2013-06-18 11:21:47

标签: exchangewebservices sharepoint-2013

我正在使用EWS从网页发送电子邮件。当我在控制台应用程序中运行此代码时,它已成功执行:

var sender = "sample@mail.com";
var fromPassword = "pass";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials(sender, fromPassword);
service.Url = new Uri("https://testserver.com/EWS/Exchange.asmx");
ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
           X509Certificate certificate, X509Chain chain,
           SslPolicyErrors sslPolicyErrors)
        {
            return true;
        };

EmailMessage message = new EmailMessage(service);
message.Subject = "test";
message.Body = "test";
message.ToRecipients.Add("sample@gmail.com");
message.SendAndSaveCopy();

当我在我的sharepoint应用程序中从网页运行相同的代码时,当SendAndSaveCopy方法执行时,我收到错误“401 unauthorized”。

我做错了什么?

感谢。

0 个答案:

没有答案