2
这段代码给我一些问题,当我运行它。它不发送消息,它说错误在smtp.Send(mm);我解决不了当我运行这段代码时,它给出了错误(smtp.Send(mm);)我不知道如何解决它
if (!string.IsNullOrEmpty(password))
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage("[email protected]", 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 = "[email protected]";
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.";
}
}
你的问题与'asp.net'或'sql-server'有什么关系? – Luiso
什么是错误?你能把异常信息放入问题中吗? –
如果您启用SSL,请尝试使用端口465。如果您禁用SSL使用端口587 – MIKE