当前位置: 首页 > 知识库问答 >
问题:

使用C#发送电子邮件SMTP服务器需要安全连接或客户端未通过身份验证[重复]

万博涛
2023-03-14

我正在使用C#创建示例电子邮件发送器,但它显示一个错误是:

SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要身份验证。

private void SendHtmlFormattedEmail(string recepientEmail, string subject, string body)
{
    using (MailMessage mailMessage = new MailMessage())
    {
       mailMessage.From = new MailAddress("sysumurugan@gmail.com");
       mailMessage.Subject = subject;
       mailMessage.Body = body;
       mailMessage.To.Add(new MailAddress(recepientEmail));
       SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
       smtp.EnableSsl = true;
       smtp.UseDefaultCredentials = false;
       System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential("sysumurugan@gmail.com", "XXXXXXXXX");
       smtp.Credentials = NetworkCred;
       smtp.Timeout = 10000;
       smtp.Send(mailMessage);
    }
}

请帮助我获取邮件发件人代码示例

状态:System.Net.Mail.SMTPStatusCode.MusTissuestarttlsFirst

共有1个答案

段干浩荡
2023-03-14

试着交换这些行,如下所示:

smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential NetworkCred = new    System.Net.NetworkCredential("sysumurugan@gmail.com", "XXXXXXXXX");
 类似资料: