3

I am using EWS for sending email from web page. When I run this code in console application It's successfuly executed:

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();

When I run the same code from web page in my sharepoint application I get error "401 unauthorized" when SendAndSaveCopy method executing.

What I am doing wrong?

Thanks.

asolovyov
  • 903
  • 1
  • 10
  • 21
  • possible duplicate of [Exchange Web Service API and 401 unauthorized exception](http://stackoverflow.com/questions/13517323/exchange-web-service-api-and-401-unauthorized-exception) – Shadow The GPT Wizard May 25 '14 at 08:08

0 Answers0