1
嗨,我使用下面的代码发送预订形式,但它在本地工作,但是当我把它活了失败,不知道为什么:发送带有C#本地工作,但静静地失败过
保护无效的Page_Load(对象发件人,EventArgs的){
}
protected void SendMail()
{
var sDate = startDate.Text;
var eDate = endDate.Text;
// Gmail Address from where you send the mail
var fromAddress = "[email protected]";
// any address where the email will be sending
var toAddress = "[email protected]";
//Password of your gmail address
const string fromPassword = "xxx";
// Passing the values and make a email formate to display
string subject = YourSubject.Text.ToString();
string body = "From: " + YourName.Text + "\n";
body += "Email: " + YourEmail.Text + "\n";
body += "Contact Number: " + txtContactNumber.Text + "\n";
body += "Subject: " + YourSubject.Text + "\n";
body += "Question: \n" + Comments.Text + "\n";
body += "Pet Name(s): \n" + txtPetName.Text + "\n";
body += "Start Date: \n" + sDate + "\n";
body += "End Date: \n" + eDate + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//here on button click what will done
SendMail();
DisplayMessage.Text = "Thank you for contacting us we will get back to you shortly. If you would like to talk to us, please call 0208 236 9572";
DisplayMessage.Visible = true;
YourSubject.Text = "";
YourEmail.Text = "";
YourName.Text = "";
Comments.Text = "";
}
catch (Exception) { }
}
它不发送消息或显示“感谢您联系......”
这是网站www.silverhillcattery.co .uk
任何帮助将不胜感激!
更新:
我加入了错误信息的建议,我现在得到以下错误:
“SMTP服务器要求安全连接或客户端未通过身份验证”
我将研究这个问题。