我有一个通用邮箱,可用于从我的网站发送电子邮件。它已停止工作并引发异常。以下是错误截图。
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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3f3d2e392a2a212b2e21262a2377790f28222e2623612c2022" rel="noreferrer noopener nofollow">[email protected]</a>"));
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 客户端的错误,如何检查其是否工作正常?谢谢。
最佳答案
您没有设置 Network Credentials 。换句话说,您没有验证电子邮件。
NetworkCredential myCredentials = new NetworkCredential(
"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6cbdfc3cbc7cfcae6c2c9cbc7cfc888c5c9cb" rel="noreferrer noopener nofollow">[email protected]</a>","myPassword","mail.myDomainName.com");
client.Credentials = myCredentials;
关于c# - 由于 SMTP 异常,电子邮件未发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16144077/