C# 邮件无法到达电子邮件
我正在尝试在我的网站上建立一个联系表单,我使用asp.net和C#,当我提交邮件时,它没有到达电子邮件,是因为我使用的是本地服务器吗?或者我的代码中有错误?我在catch部分收到一条错误消息:“您的消息发送失败,请重试。” 这是C页后面的代码# 这是个例外 System.Net.Mail.SmtpException:SMTP服务器需要安全的 连接或客户端未通过身份验证。服务器响应 was:5.5.1需要身份验证。了解更多信息,请访问 System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode状态码, 字符串响应)在System.Net.Mail.MailCommand.Send(SmtpConnection)中 conn,Byte[]命令,MailAddress from,布尔allowUnicode)位于 System.Net.Mail.SmtpTransport.SendMail(邮寄地址发送者, MailAddressCollection收件人,字符串deliveryNotify,布尔值 allowUnicode、SmtpFailedRecipientException和exception)在 System.Net.Mail.SmtpClient.Send(MailMessage)位于 Default2.btnSubmit\u在 c:\Users\looly\Documents\Visual Studio 2015\WebSites\WebSite6\Default2.aspx.cs:第46行 服务器响应为:5.5.1身份验证 基于此错误,请检查以下步骤C# 邮件无法到达电子邮件,c#,asp.net,email,C#,Asp.net,Email,我正在尝试在我的网站上建立一个联系表单,我使用asp.net和C#,当我提交邮件时,它没有到达电子邮件,是因为我使用的是本地服务器吗?或者我的代码中有错误?我在catch部分收到一条错误消息:“您的消息发送失败,请重试。” 这是C页后面的代码# 这是个例外 System.Net.Mail.SmtpException:SMTP服务器需要安全的 连接或客户端未通过身份验证。服务器响应 was:5.5.1需要身份验证。了解更多信息,请访问 System.Net.Mail.MailCommand.Che
- 输入正确的登录密码
- 删除两步验证
- 您必须为您的google启用从其他时区/ip登录 帐户。要执行此操作,请按照 并通过单击“继续”按钮允许访问
- 转到以下位置的安全设置并启用不太安全的应用程序。这样您就可以从所有应用程序登录
服务器响应为:5.5.1需要身份验证。
我更新了帖子,equalsk您是对的:D
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.";
}