client.Send(mail);
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 at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at check_email.Email.Unnamed_Click(Object sender, EventArgs e) in c:\users\anwar ali\documents\visual studio 2015\Projects\check_email\check_email\Email.aspx.cs:line
string pweda = "password"; //(ConfigurationManager.AppSettings["password"]); string from = "from@gmail.com"; //Replace this with your own correct Gmail Address string to = "to@gmail.com"; System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new MailAddress(from); mail.Subject = "This is a test mail"; mail.SubjectEncoding = System.Text.Encoding.UTF8; mail.Body = "Test Mail."; mail.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); //Add the Creddentials- use your own email id and password client.UseDefaultCredentials = false; client.Credentials = new System.Net.NetworkCredential(from, pweda); client.Port = 587; // Gmail works on this port client.Host = "smtp.gmail.com"; client.EnableSsl = true; //Gmail works on Server Secured Layer try { client.Send(mail); Response.Write("Message Sent..."); } catch (Exception ex) { Exception ex2 = ex; string errorMessage = string.Empty; while (ex2 != null) { errorMessage += ex2.ToString(); ex2 = ex2.InnerException; } HttpContext.Current.Response.Write(errorMessage); }
Turn On
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)