我必须使用我的网络应用程序发送邮件.鉴于以下代码显示SMTP服务器需要安全连接或客户端未经过身份验证.服务器响应是: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL
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系统上的真实地址.
如果您将电子邮件地址硬编码为from和office 365密码,则可以验证.当然,不要把它留在那里.