0
我在使用SMTP發送電子郵件時遇到問題,它說「等待本地主機」然後最終超時。在Visual Studio 2012中使用SMTP
我的假設是,SMTP是本地主機上禁用了,所以我必須看看這裏的方向:http://msdn.microsoft.com/en-us/library/8b83ac7t%28v=vs.100%29.aspx但沒有一個步驟是適用於我的計算機(Windows 8,asp.net 4,VS 2012)
這是默認啓用,問題是我的代碼? 這裏是我的代碼
protected void SendMail()
{
MailMessage email = new MailMessage();
email.To.Add(new MailAddress("removed"));
email.Subject = "Contact Form";
email.From = new MailAddress(emailTextbox.Text);
email.Body = "From: " + nameTextbox.Text + "<br />";
email.Body = "Message: " + commentTextbox.Text + "<br />";
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 465;
smtp.Credentials = new NetworkCredential("removed", "removed");
smtp.EnableSsl = true;
smtp.Send(email);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SendMail();
messageLabel.Text = "Thanks for your email, we will get back to you shortly.";
}
catch (Exception error) {
messageLabel.Text = "Error " + error;
}
}
任何幫助表示感謝,謝謝!
嗯,真的很奇怪,你在哪裏看到「等待localhost」的?你的代碼不會在任何地方調用localhost,它應該直接調用smtp.gmail.com ...也許你的機器中配置了代理服務器? – Gusman
哦,好吧,我明白了,這是asp,沒有注意到,嘿嘿。 – Gusman
你究竟得到了什麼異常? – Gusman