Hello Guys,
i am having problem while writing codes to implement mail messeging in asp .net with c#
i am using following code
try{
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);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
catch(Exception ex)
{
Response.Write("");
}
The error i am facing is
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. ra13sm19230672pac.29 - gsmtp


Midhun TpRank #388 · 6.5K reputationPosted Oct 6, 2016, 12:18 AM EDT
Ankit KumarRank #6,715 · 258 reputationPosted Oct 6, 2016, 12:40 AM EDT
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Oct 6, 2016, 2:35 AM EDT
Ananth GRank #1,176 · 1.5K reputationPosted Oct 20, 2016, 8:59 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Oct 21, 2016, 12:52 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Oct 6, 2016, 1:31 AM EDT