【问题标题】:How to resolved Office 365 SMTP Mail Error in C#如何解决 C# 中的 Office 365 SMTP 邮件错误
【发布时间】:2020-05-06 06:25:28
【问题描述】:

我正在使用 office365 发送邮件,如下代码


    MailMessage msg = new MailMessage();
    msg.To.Add(new MailAddress("*******", "*********"));
    msg.From = new MailAddress("******", "*******");
    msg.Subject = "This is a Test Mail";
    msg.Body = "This is a test message using Exchange OnLine";
    msg.IsBodyHtml = true;

    SmtpClient client = new SmtpClient();
    client.UseDefaultCredentials = false;
    client.Credentials = new System.Net.NetworkCredential("******", "********");
    client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
    client.Host = "d*******.mail.protection.outlook.com";//"smtp.office365.com";//
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = true;

    client.Send(msg);

当我使用smtp.office365.com 时,我遇到了以下问题

SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 SMTP;客户不是 在 MAIL FROM 期间经过身份验证以发送匿名邮件 [BM1PR01CA0089.INDPRD01.PROD.OUTLOOK.COM]

如果我使用d**********.mail.protection.outlook.com,那么我得到了

无法从传输连接读取数据:net_io_connectionclosed。

【问题讨论】:

    标签: office365


    【解决方案1】:

    尝试通过向上移动一些属性设置器来重新排序:

    MailMessage msg = new MailMessage();
        msg.To.Add(new MailAddress("*******", "*********"));
        msg.From = new MailAddress("******", "*******");
        msg.Subject = "This is a Test Mail";
        msg.Body = "This is a test message using Exchange OnLine";
        msg.IsBodyHtml = true;
    
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential("******", "********");
        client.EnableSsl = true;
        client.UseDefaultCredentials = false;    
        client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
        client.Host = "d*******.mail.protection.outlook.com";//"smtp.office365.com";//
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.Send(msg);
    

    另外,您可以查看一个类似的帖子 - The server response was: 5.7.0 Must issue a STARTTLS command first. i16sm1806350pag.18 - gsmtp

    similar forum threads

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 2018-01-31
      • 2016-06-15
      • 1970-01-01
      相关资源
      最近更新 更多