3

我正在使用 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();

当我在共享点应用程序中从网页运行相同的代码时,执行 SendAndSaveCopy 方法时出现错误“401 未授权”。

我做错了什么?

谢谢。

4

0 回答 0