我有一个可用于从我的网站发送电子邮件的常规邮箱。它已停止工作并抛出异常。以下是错误的屏幕截图。
error http://img7.imageshack.us/img7/7227/42097647.png
代码是
protected void Submit_Click(object sender, EventArgs e)
{
if (ValidateBox.Text == "6")
{
MailMessage message = new MailMessage();
message.From = new MailAddress(EmailBox.Text.ToString());
message.To.Add(new MailAddress("praveendaniel86@gmail.com"));
message.Subject = "Message via CAM Website General Mailbox";
string body = "Name: " + NameBox.Text.ToString() + Environment.NewLine + Environment.NewLine +
"Home Tel: " + HomeTelBox.Text.ToString() + Environment.NewLine + Environment.NewLine +
"Work Tel: " + WorkTelBox.Text.ToString() + Environment.NewLine + Environment.NewLine +
"Comment/Question: " + CommentBox.Text.ToString();
message.Body = body;
SmtpClient client = new SmtpClient();
client.Send(message);
Response.Redirect("~/Thank-You.aspx");
}
else
{
Label1.Visible = true;
}
}
这可能是我的webconfig中提到的SMTP客户端的错误,我如何检查它是否正常工作?感谢。
答案 0 :(得分:1)
您没有设置Network Credentials。换句话说,您没有对电子邮件进行身份验证。
NetworkCredential myCredentials = new NetworkCredential(
"myemail@domain.com","myPassword","mail.myDomainName.com");
client.Credentials = myCredentials;
答案 1 :(得分:1)
这是配置问题。
您的web.config(system.net> mailSettings> smtp)中指定的SMTP服务器未配置为进行中继。您有两种方法可以解决此问题: