Karthik K

Karthik K

  • 935
  • 738
  • 186.3k

Email Sending Error ..

Jun 3 2017 1:49 AM
 
Hi ,
 
   I had a issue while i develop the Email sending , i Am facing the problem..in the below code Kindly Help me out .
 
Code sample :  
 
protected void SendEmail(object sender, EventArgs e)
{
string to = txtTo.Text;
string from = txtEmail.Text;
string subject = txtSubject.Text;
string body = txtBody.Text;
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "Smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);    In this like Error is occured 
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
 
Error :
 
 

he SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

 
If possible , Guid me properly , with the appropriate change . 
 
 
Thanks in advance 
 
 
 
 
 
 
 
 
 

Answers (3)