服务器响应是:5.7.57 SMTP; 客户端未通过身份validation,无法在MAIL FROM期间发送匿名邮件

我必须使用我的网络应用程序发送邮件。 鉴于以下代码显示The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM错误The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM 。 帮我找到合适的解决方案。 谢谢。

码:

 protected void btnsubmit_Click(object sender, EventArgs e) { Ticket_MailTableAdapters.tbl_TicketTableAdapter tc; tc = new Ticket_MailTableAdapters.tbl_TicketTableAdapter(); DataTable dt = new DataTable(); dt = tc.GetEmail(dpl_cate.SelectedValue); foreach (DataRow row in dt.Rows) { string eml = (row["Emp_Email"].ToString()); var fromAddress = "emailAddress"; var toAddress = eml; const string fromPassword = "*****"; string body = "Welcome.."; // smtp settings var smtp = new System.Net.Mail.SmtpClient(); { smtp.Host = "smtp.office365.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(fromAddress, fromPassword); smtp.UseDefaultCredentials = false; smtp.Timeout = 600000; } // Passing values to smtp object smtp.Send(fromAddress, toAddress, subject, body); } } } 

我可能不是一个优秀的程序员,但你似乎将From地址作为“emailAddress”传递,这不是一个正确的电子邮件地址,而对于Office365来说,需要成为Office365系统上的真实地址。

如果您将电子邮件地址硬编码为来自和办公室365密码,则可以validation。 当然,不要把它留在那里。

@Reshma-如果你还没有想到它,这里有我试过的东西,它解决了同样的问题。

  1. 确保您设置的NetworkCredentials正确无误。 例如,在我的情况下,因为它是办公室SMTP,因此必须在NetworkCredential中使用用户ID以及域名而不是实际的电子邮件ID。

  2. 您需要先将“UseDefaultCredentials”设置为false,然后设置Credentials。 如果之后设置“UseDefaultCredentials”,它会将NetworkCredential重置为null。

希望能帮助到你。

我花了太多时间在这上面,解决方案非常简单。 我不得不使用我的“MX”作为主机和端口25。

  var sClient = new SmtpClient("domain-com.mail.protection.outlook.com"); var message = new MailMessage(); sClient.Port = 25; sClient.EnableSsl = true; sClient.Credentials = new NetworkCredential("user", "password"); sClient.UseDefaultCredentials = false; message.Body = "Test"; message.From = new MailAddress("test@test.com"); message.Subject = "Test"; message.CC.Add(new MailAddress("dude@good.com")); sClient.Send(message); 

我用来解决同样的问题。

添加域名解决了..

 mySmtpClient.Credentials = New System.Net.NetworkCredential("email@domain.com", "password", "domain.com") 

仅在上述评论中提到的两个主要原因

  1. 您设置的NetworkCredentials应该是正确的。 validation尝试实际登录帐户。
  2. 您需要先将UseDefaultCredentials设置为false,然后设置Credentials或Put smtp.UseDefaultCredentials = false;smtp.Credentials assignment之上。

这是一个老问题,但由于这是谷歌第一次出现此错误的结果,我想我会更新我在这个问题上的进展。

我在这个问题上花了不少时间。 最后,我不得不多次更改Office 365帐户的密码,直到我的代码成功发送电子邮件。

没有必要对代码进行任何更改。

如果您使用的是Office 365,请按照以下步骤操作:

  1. 使用Azure power shell检查密码到期时间:Get-MsolUser -All | 选择DisplayName,LastPasswordChangeTimeStamp
  2. 使用新密码(不是旧密码)更改密码。 您最终可以返回旧密码,但需要更改两次。

希望能帮助到你!

添加属性后开始工作:

 mail.smtp.starttls.enable=true 

使用:

 mail.smtp.host=smtp.office365.com mail.smtp.port=587 mail.transport.protocol=smtp mail.smtp.auth=true mail.smtp.starttls.enable=true mail.smtp.user=xxx@example.com mail.smtp.password=xxx mail.smtp.from=yyy@example.com 

我更改了Office365密码,然后尝试发送测试邮件,它对我来说就像一个魅力。

我使用前端(数据库邮件选项)和设置为smtp.office365.com端口号587并检查了安全连接选项。 使用基本身份validation并存储凭据。 希望这对某人有用。

在我的情况下,我使用MailMessage构造函数,它接受两个字符串(to,from)并获得相同的错误。 当我使用默认构造函数然后将MailAddress对象添加到MailMessage的To属性时,它工作正常。