我正在使用Visual Studio 2010.我正在尝试在用户点击提交时向1个电子邮件地址发送电子邮件。我收到以下错误:
错误:语法错误,命令无法识别。服务器响应为:5.0.0您的电子邮件系统必须在发送邮件之前进行身份验证:
这是我的代码背后的代码:
public void SendMail(string FromEmail, string ToEmail, string Subject, string Body)
{
System.Net.Mail.MailMessage eMail = new System.Net.Mail.MailMessage();
eMail.From = new System.Net.Mail.MailAddress(FromEmail);
//MailMessage eMail = new MailMessage();
//eMail.From = new MailAddress(FromEmail);
eMail.To.Add(ToEmail);
eMail.Subject = Subject;
eMail.IsBodyHtml = true;
eMail.Body = Body;
SmtpClient SMTP = new SmtpClient();
//SMTP.Host = "mail.authsmtp.com";
//SMTP.UseDefaultCredentials = true;
//SMTP.EnableSsl = true;
SMTP.Send(eMail);
eMail.Dispose();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
StringBuilder sbBody = new StringBuilder();
string FromEmail = "smit@college.edu";
string ToEmail = "smit@college.edu";
string Subject = "Application for" + " " + txtFirstName.Text + " " + txtLastName.Text + " " + "created on:" + " " + txtDateCreated.Text;
sbBody.Append("Click link below to view application for" + " " + txtFirstName.Text + " " + txtLastName.Text);
sbBody.Append("<br/>");
sbBody.Append("<br/>");
sbBody.Append("AdminDisplay.aspx?ID=@ID");
sbBody.Append("<br/>");
sbBody.Append("Thank you,");
sbBody.Append("Admin");
SendMail(FromEmail, ToEmail, Subject, sbBody.ToString());
}
这是我的web.config:
<system.net>
<mailSettings>
<smtp from="smit@college.edu">
<network host="mail.authsmtp.com" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
我一直在努力工作,需要让它发挥作用。谢谢