【发布时间】:2022-11-08 18:13:17
【问题描述】:
任何人都可以帮忙。
我正在使用以下代码从生成错误的 ASP.Net、C# Web 表单应用程序发送电子邮件。相同的代码适用于其他应用程序。我的域名中包含一个连字符 (-)。是这个原因吗?我是否需要查看电子邮件配置或服务器/域级别设置?请帮忙。
string smtpServer = "smtp.office365.com";
int port = 587;
using (MailMessage mail = new MailMessage())
{
using (SmtpClient SmtpServer = new SmtpClient(smtpServer))
{
mail.From = new MailAddress(_emailIDFrom);
mail.To.Add(_emailIDTo);
mail.Subject = _subject;
mail.IsBodyHtml = true;
mail.Body = _emailBody;
SmtpServer.Port = port;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(_emailIDFrom, _emailIDFromPassword);
SmtpServer.EnableSsl = true;
try
{
SmtpServer.Send(mail);
return true;
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
return false;
}
}
}
我在 Global.asax Application_Start 中的 Tls 代码如下
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
{
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
}
错误 - SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 客户端未通过身份验证发送邮件。错误:535 5.7.139 身份验证不成功,租户的 SmtpClientAuthentication 已禁用。访问https://aka.ms/smtp_auth_disabled 了解更多信息。 [DXXP273CA0023.AREP273.PROD.OUTLOOK.COM]
【问题讨论】:
-
任何人都可以帮助我吗?
-
你已经解决了吗?
标签: asp.net c#-4.0 exchange-server c#-3.0 c#-2.0