Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi
i create a mail code like

MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txt_email.Text.ToString());
loginInfo.From = new MailAddress("my email id");
loginInfo.Subject = "Contact Detail";
loginInfo.Body = "Message: " + txt_message.Text; 
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("my user name", "My password");
smtp.Send(loginInfo);



and it's work properly in localhost but i host this application and send mail when error are come like this

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

Source Error:


Line 32:         smtp.EnableSsl = true;
Line 33:         smtp.Credentials = new System.Net.NetworkCredential("my id", "my pwd");
Line 34:         smtp.Send(loginInfo);
Line 35:     }
Line 36: }
Posted
Updated 15-Feb-13 1:53am
v4

You need to add the following code and execute once for your application context.

C#
System.Net.ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;


Actaully when use ssl then it use certificate and your web server try to validate that. In the above code you validated all certificates with true value. Please add this code to your Applicatin start event or some other place and redeploy the code and test it.
 
Share this answer
 
Check the below link. It shows the example of gmail.

sendind mail using smtp in asp.net[^]

You can also try the below its Gmail APIs
https://developers.google.com/google-apps/gmail/[^]
 
Share this answer
 
v2

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