- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 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/
我是一名优秀的程序员,十分优秀!