c#用smtp发送outlook邮件失败

账号密码正确无误,使用了密码和应用密码都试过了。UseDefaultCredentials属性false,true,注释掉都试过了,还是发送失败

代码:

 

https://blog.csdn.net/u012842630/article/details/103248204/

我用下面的代码测试,邮箱为Hotmail发是正常的,你可以试试

 public ActionResult SendMail()
        {
            Encoding utf8 = Encoding.UTF8;
            MailMessage mail = new MailMessage
            {
                From = new MailAddress("xxxx@hotmail.com"),
                Subject = "From Asp.net Mailer",
                IsBodyHtml = true,
                Body = "来自Asp.net MailMessage发送的内容",
                SubjectEncoding = utf8,
                BodyEncoding = utf8
            };
            mail.To.Add("xxxxx@qq.com");


            var s = "邮件发送成功!";
            SmtpClient client = new SmtpClient
            {
                //Host = "smtp-mail.outlook.com",
                Host = "smtp.office365.com",
                Port = 587,
                EnableSsl = true,
                UseDefaultCredentials = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials = new NetworkCredential("xxxx@hotmail.com", "xx密码xx")
            };
            try
            {
                client.Send(mail);
            }
            catch (Exception ex) { s = ex.Message; }
            return Content(s);
        }