Im Develop the Asp.net web application. im Add the Email part, i had a following error cant sent the email.
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
Im try to fix it more than 5 hours, but i cant fix this, i was refer all of Stack overflow question
class
public static void SendEmail(string receientEmail, string subject, string body) {
//Email
using (MailMessage mailMessage = new MailMessage()) {
mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["UserName"]);
mailMessage.Subject = subject;
mailMessage.Body = body;
mailMessage.IsBodyHtml = true;
mailMessage.To.Add(new MailAddress(receientEmail));
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["Host"];
smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = ConfigurationManager.AppSettings["UserName"];
NetworkCred.Password = ConfigurationManager.AppSettings["Password"];
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
smtp.Send(mailMessage);
}
WebConfig
<appSettings>
<add key="AdminLoginID" value="admin"/>
<add key="AdminPassword" value="123"/>
<!--Email Setting-->
<add key ="Host" value="smtp.gmail.com"/>
<add key ="EnableSsl" value="true"/>
<add key ="UserName" value="cafe****@gmail.com"/>
<add key ="Password" value="****"/>
<add key ="Port" value="587"/>
</appSettings>