问题描述
我必须使用我的网络应用程序发送邮件.鉴于以下代码显示 SMTP 服务器需要安全连接或客户端未通过身份验证.服务器响应是:
I have to send mails using my web application. Given the below code showing The SMTP server requires a secure connection or the client was not authenticated. The server response was:
5.7.57 SMTP;在 MAIL FROM 期间,客户端未通过身份验证发送匿名邮件.
5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM.
帮助我找到合适的解决方案.谢谢.
Help me to find a proper solution. Thank you.
代码:
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,From
需要是 Office365 系统上的真实地址.
You seem to be passing the From
address as emailAddress
, which is not a proper email address. For Office365 the From
needs to be a real address on the Office365 system.
如果您将电子邮件地址硬编码为 From
和 Office 365 密码,则可以验证这一点.
You can validate that if you hardcode your email address as the From
and your Office 365 password.
当然不要把它留在那里.
Don't leave it there though of course.
这篇关于5.7.57 SMTP - 在 MAIL FROM 错误期间,客户端未通过身份验证发送匿名邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!