This code is giving me some problems when I run it. It does not send the message and it says that the error is on smtp.Send(mm); and I can't solve it
if (!string.IsNullOrEmpty(password))
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage("eden.elao@gmail.com", Username.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi {0},<br /><br />Your password is {1}.<br /><br />Thank You.", username, password);
mm.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "sender@gmail.com";
NetworkCred.Password = "<Password>";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm); // the error is here.
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "Password has been sent to your email address.";
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "This email address does not match our records.";
}
}