我幾乎沒有使用C#的經驗,而且我目前在將按鈕發送到指定地址的電子郵件時遇到問題。無法通過點擊按鈕發送電子郵件。 ASP.NET和C#
我有一個包含聯繫表單的ASP.NET網頁。我想讓用戶在文本框中輸入數據,然後當他們點擊「發送」按鈕時,這些信息通過電子郵件發送。
但是,當我點擊發送我得到以下。
連接嘗試失敗,因爲連接的方沒有正確一段時間後響應或已建立的連接失敗,因爲連接的主機未能響應209.85.229.109:25
的C#代碼如下。
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(txtemail.Text);
mail.To.Add("[email protected]");
mail.Subject = "Taxi Taxi Support";
mail.IsBodyHtml = true;
mail.Body = "First Name: " + txtname.Text;
mail.Body += "Email: " + txtemail.Text;
mail.Body += "Comments: " + txtquestion.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Send(mail);
}
我使用System.Net和System.Net.Mail
任何幫助將不勝感激。
[通過Gmail以.NET發送電子郵件]或[this](http:// stackoverflow.com/questions/704636/sending-email-through-gmail-smtp-server-with-c)或[this](http://stackoverflow.com/questions/2551926/sending-email-through-gmail) – 2011-05-31 15:48:58