我正在尝试在我的网站上建立联系表单,我正在使用带有C#的asp.net,当我提交邮件时它没有到达电子邮件,是因为我使用本地服务器?或者我的代码有错误?我在catch部分收到此错误消息:“您的消息无法发送,请再试一次。”
这是页面C#
背后的代码try
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("jasmine.afnan@gmail.com");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("jasmine@gmail.com");
msg.From = address;
//Append their name in the beginning of the subject
msg.Subject = txtName.Text + " : " + ddlSubject.Text;
msg.Body = txtMessage.Text;
//Configure an SmtpClient to send the mail.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true; //only enable this if your provider requires it
//Setup credentials to login to our sender email address ("UserName", "Password")
NetworkCredential credentials = new NetworkCredential("jasmine.afnan@gmail.com", "*");
client.Credentials = credentials;
//Send the msg
client.Send(msg);
//Display some feedback to the user to let them know it was sent
lblResult.Text = "Your message was sent!";
//Clear the form
txtName.Text = "";
txtMessage.Text = "";
}
catch
{
//If the message failed at some point, let the user know
lblResult.Text = "Your message failed to send, please try again.";
}
这是例外
System.Net.Mail.SmtpException:SMTP服务器需要安全 连接或客户端未经过身份验证。服务器响应 是:5.5.1需要身份验证。了解更多信息 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, System.Net.Mail.MailCommand.Send的字符串响应(SmtpConnection conn,Byte []命令,MailAddress from,Boolean allowUnicode)at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection收件人,String deliveryNotify,布尔值 allowUnicode,SmtpFailedRecipientException&例外) System.Net.Mail.SmtpClient.Send(MailMessage消息)at Default2.btnSubmit_Click(Object sender,EventArgs e)in c:\ Users \ looly \ Documents \ Visual Studio 2015 \ WebSites \ WebSite6 \ Default2.aspx.cs:第46行
答案 0 :(得分:0)
服务器响应为:5.5.1身份验证
根据此错误。您检查以下步骤。