what is the error in this code please explain it and give the correct code to send email to the desired email in asp.net web application.
SmtpClient smtp;
MailMessage mail = new MailMessage();
String strEmailHeader;
String strFromEmail = "balayogistark@gmail.com";
try
{
mail.From = new MailAddress("balayogistark@gmail.com","Balayogi");
mail.To.Add(new MailAddress(txtmail.Text, txtusername.Text));
mail.ReplyTo = new MailAddress("balayogistark@gmail.com");
mail.Subject = " Link to change your password ";
String msg = "click this link to change your password http://localhost:54079/Account/passwordupdatepage.aspx";
mail.Body = msg;
mail.IsBodyHtml = true;
mail.BodyEncoding = System.Text.Encoding.UTF8;
smtp = new SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
strEmailHeader = strFromEmail.Substring(0, strFromEmail.Length - 10);
smtp.Credentials = new System.Net.NetworkCredential(strEmailHeader, "batman2016");
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(mail);
Response.Write("Go to your mail");
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
Aucun commentaire:
Enregistrer un commentaire