Click here to Skip to main content
15,886,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi every body,
Please help me why i build a project to send mail, when i run at my computer that ok, So i run on another server have a error "The remote server returned an error: (401) Unauthorized.". I dont know that is my code error or server config my account.
This is my code
C#
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
              ExchangeService service = new ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2007_SP1);

              service.Credentials = new WebCredentials(@"domain\myuser", "mypass");

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

              EmailMessage email = new EmailMessage(service);
              email.ToRecipients.Add(MrK, mrk@domain.com);
              email.Subject = "Test From Smart's Server";
              email.Body = new MessageBody(string.Format(_body_mail, prnumber, "hey you", purposeofpur));
              email.Send();

Thank you so much
Posted
Comments
Kornfeld Eliyahu Peter 25-Feb-14 2:59am    
The URI and the credentials are fixed? Or d oyou have others for the other server?
Ziee-M 25-Feb-14 3:35am    
There are a lot of cases for the code to return (401) Unauthorized in the server while it works in local.
enable SSl, try changing the default Port(587 or 25). and finally you have to precisze the Host.
Keep doing tests.

1 solution

yeah, i really done already. thank so much all, it error because my user on server should'nt have domain\
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900