c# - Azure 函数 : Client was not authenticated to send anonymous mail during MAIL FROM [DB6P189CA0021. EURP189.PROD.OUTLOOK.COM]

标签 c# azure azure-functions

我想在 Azure Function 中发送电子邮件。我写下下面的代码。 它在控制台应用程序中正常工作并且我能够使用凭据发送电子邮件。但是当我在 Azure Function 中测试相同的代码时,它抛出了以下错误。

Exception while executing function: Functions.HttpTriggerCSharp. Microsoft.Azure.WebJobs.Script: One or more errors occurred. f-HttpTriggerCSharp__-1774598883: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [DB6P189CA0021.EURP189.PROD.OUTLOOK.COM]

我使用的代码 -

 SmtpClient client = new SmtpClient("smtp-mail.outlook.com");
        string _sender = "--email--";
        string _password = "-password---";
        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        System.Net.NetworkCredential credentials =
            new System.Net.NetworkCredential(_sender, _password);
        client.EnableSsl = true;
        client.Credentials = credentials;
        string recipient = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5974742d3c2a2d19362c2d35363632773a36347474" rel="noreferrer noopener nofollow">[email protected]</a>";
            string subject="Temperature of device exceeds";
        string message="Temperature of device exceeds";
        try
        {
            var mail = new MailMessage(_sender.Trim(), recipient.Trim());
            mail.Subject = subject;
            mail.Body = message;
            client.Send(mail);
        }
        catch (Exception ex)
        {

        }

最佳答案

我使用队列触发器并在我的 azure 函数(v1)中遵循您的代码,效果很好。

The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

此消息表明您的外发邮件帐户中配置的 SMTP 服务器正在连接到无法用于直接发送的 SMTP 客户端提交端点。

将您的 Exchange SMTP 配置为直接发送。

配置电子邮件通知在DS-Client >设置>配置>通知中选择SMTP,添加SMTP服务器设置并选择添加SMTP服务器设置 服务器需要身份验证。

在SMTP服务器验证窗口中添加office365验证的帐户信息。

有关详细信息,请参阅以下 Microsoft 文章:

Fix issues with printers, scanners, and LOB applications that send email using Office 365

How to set up a multifunction device or application to send email using Office 365

关于c# - Azure 函数 : Client was not authenticated to send anonymous mail during MAIL FROM [DB6P189CA0021. EURP189.PROD.OUTLOOK.COM],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50623880/

相关文章:

c# - "(n, index) => n >= index"在 LINQ 中是什么意思?

c# - 用于包装 JsonResult 操作响应的 .Net 过滤器

azure - Azure 移动服务中的增量加载

azure - Microsoft 视频索引器无法进行日语转录

json - 具有 HTTP 触发器和 Blob 输入绑定(bind)的 Azure 函数 - 无法读取文件夹中的 JSON 文件。可能的 blob 文件路径错误?

c# - 如何从Windows Phone的其他页面引用应用程序中的属性,全局变量

C# 使用哪个循环?

java - 有没有办法使用 Java 程序在 Microsoft Azure 中创建虚拟机?

azure - Visual Studio Code 找不到 Azure 函数上传订阅

azure - 防止 Azure Live Metrics Stream 将每个轮询记录到队列