我有一个情况。HTML 代码是标准的,带有三个文本框和一个按钮:
<add key="cma_contact_form_email" value="somec@gmail.com"/>
<add key="cma_contact_to_address" value="some@gmail.com"/>
<add key="smtpServer" value="smtp.gmail.com" />
<add key="EnableSsl" value = "true"/>
<add key="smtpPort" value="993" />
<add key="smtpUser" value="some@gmail.com" />
<add key="smtpPass" value="pass" />
后面的代码:
protected void ImageButton_Click(Object sender, EventArgs e){
MailMessage msg = new MailMessage();
msg.To.Add(ConfigurationManager.AppSettings["cma_contact_form_email"]);
msg.From = new MailAddress(ConfigurationManager.AppSettings["cma_contact_to_address"]);
msg.Body += "Name: " + txtName.Text + "\n";
msg.Body += "Email: " + txtEmail.Text + "\n";
msg.Body += "Message: \n" + txtMessage.Text + "\n";
msg.Subject = txtName.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["smtpServer"]; //Or Your SMTP Server Address
smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]);
smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"], ConfigurationManager.AppSettings["smtpPass"]);
//Or your Smtp Email ID and Password
try
{
smtp.Send(msg);
lblPost.Text = "Thank you, your question has been submitted to our CMA heldesk.";
}
catch (Exception ex)
{
lblPost.Text = "Error occured while sending your message. " + ex.Message;
}
placeholder.Visible = false;
msgplaceholder.Visible = true;
}
通常这应该可以工作,但我得到一个超时错误。有谁知道钓点在哪里?谢谢!