Sujit Sahoo

Sujit Sahoo

  • NA
  • 206
  • 149.9k

GMAIL SMTP Error

Dec 3 2013 2:43 AM
Hi I am using this code to send mail from my ASP.net application but its showing error as I paste it below

Code to send Mail : 
  MailMessage mail = new MailMessage();
                mail.To.Add(RecipientEmail);
                mail.From = new MailAddress(ConfigurationManager.AppSettings["UserName"].ToString());
                mail.Subject = subject;

                mail.Body = MailBody;

                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = ConfigurationManager.AppSettings["Host"].ToString(); //Or Your SMTP Server Address
                smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
                smtp.Credentials = new System.Net.NetworkCredential
                     (ConfigurationManager.AppSettings["UserName"].ToString(), ConfigurationManager.AppSettings["Pwd"].ToString());
                //Or your Smtp Email ID and Password
                smtp.EnableSsl = true;
                smtp.Send(mail);

Error : 

{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, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Application.LoginForm.sendMail(String subject, String MailBody, String RecipientEmail) in C:\ApplicationSource\src\Application\LoginForm.aspx.cs:line 293}

Answers (4)