当用户在联系我们页面中单击提交时,我试图发送一封电子邮件,但由于某种原因它不起作用,我做错了什么?(此代码片段中省略了 PS 电子邮件和密码,但包含在实际解决方案中。
谢谢
web.config 中的代码:
<system.net>
<mailSettings>
<smtp from="order@test.com">
<network host="smtp.gmail.com"
userName="" //my email
password="" //password deleted for privacy reasons
defaultCredentials="false"
port="456"
enableSsl="true" />
</smtp>
</mailSettings>
asp.net 联系表中的代码:
protected void btnSubmit_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("test@gmail.com"));
mail.Subject = "Test";
mail.Body = "Message was sent from" + txtName.text + txtComment.text;
SmtpClient smtp = new SmtpClient();
smtp.SendAsync(mail, null);
}