asp.net通过office 365 smtp发送邮件

时间:2016-11-18 15:23:36

标签: asp.net email azure

我正在尝试为asp.net项目设置电子邮件通知,但它似乎无法正常工作。在localhost上它给我以下错误

5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

在azure上,它会一遍又一遍地触发可疑的登录信息。 我尝试了多个建议:

  • 端口25而不是587
  • UseDefaultCredentials true或false
  • 启用和停用SSL
似乎什么都没有用。可疑的活动邮件是我到目前为止最接近的。这是我的代码

            var client = new SmtpClient();
            client.Host = "smtp.office365.com";
            client.UseDefaultCredentials = false;
            client.Port = 587;
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("Rachelle.XXXX@outlook.com", "password");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            var message = new MailMessage("Rachelle.XXXX@outlook.com", "Rachelle_xxxxx@hotmail.com");
            message.Subject = "a ticket has been changed";
            message.Body = "Hi there, a ticket has been changed on Cronos. Please check Cronos for more details";

            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;

            try
            {
                client.Send(message);
                return message;
            }

0 个答案:

没有答案