Office365 SMTP服务器未通过身份验证

时间:2017-10-11 07:32:52

标签: c# email smtp office365 smtpclient

我正在尝试连接到 office365 的SMTP服务器,但收到以下错误。

  

SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应是:5.7.57 SMTP;客户端未通过身份验证,无法在MAIL FROM

期间发送匿名邮件

以下是相同

的代码
    public static void SendMessage()
    {

        MailMessage msg = new MailMessage();
        msg.To.Add(new MailAddress(toEmailAddress));
        msg.From = new MailAddress(fromEmailAddress);
        msg.Subject = "Test Office 365 Account";
        msg.Body = "Testing email using Office 365 account.";
        msg.IsBodyHtml = true;
        SmtpClient client = new SmtpClient();
        client.Timeout = 6000000;
        client.UseDefaultCredentials = false;
        client.Host = "smtp.office365.com";
        client.Credentials = new System.Net.NetworkCredential(username, password);
        client.Port = 587;
        client.EnableSsl = true;
        client.Send(msg);
    }

此致 @bjo

0 个答案:

没有答案