c# - sendgrid 在 Azure 功能中向多个收件人发送电子邮件失败
问题描述
(有关此问题的完整版本,请参阅 https://social.msdn.microsoft.com/Forums/en-US/20bb5b37-82af-4cf3-8a59-04e5f19572bc/send-email-to-multiple-recipients-使用-sendgrid-failure?forum=AzureFunctions )
发送给单个收件人成功。但无法在 Azure 功能中发送给多个收件人或抄送/密送。
尝试了几种格式,包括
{ "to": [{ "email": ["john.doe@example.com", "sendgridtesting@gmail.com" ] }] }
这似乎是天蓝色功能的极限。但还不确定哪里出了问题。请参阅下面的“绑定”,
{
"bindings": [
{
"name": "telemetryEvent",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "threshold-email-queue",
"connection": "RootManageSharedAccessKey_SERVICEBUS",
"accessRights": "Manage"
},
{
"type": "sendGrid",
"name": "$return",
"apiKey": "SendGridKey",
"direction": "out",
"from": "ABC@sample.com",
"to": [{
"email": ["test1@sample1.com", "test2@sample2.com" ]
}]
}
],
"disabled": false
}
解决方案
我使用 HTTP 触发器做了我的示例,但基于此,您将能够使其与服务总线触发器一起使用。
我的function.json:
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"type": "sendGrid",
"name": "mails",
"apiKey": "MySendGridKey",
"direction": "out",
"from":"samples@functions.com"
}
],
"disabled": false
}
我的 run.csx:
#r "SendGrid"
using System;
using System.Net;
using SendGrid.Helpers.Mail;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ICollector<Mail> mails)
{
log.Info("C# HTTP trigger function processed a request.");
Mail message = new Mail()
{
Subject = $"Hello world from the SendGrid C#!"
};
var personalization = new Personalization();
personalization.AddTo(new Email("foo@bar.com"));
personalization.AddTo(new Email("foo2@bar.com"));
// you can add some more recipients here
Content content = new Content
{
Type = "text/plain",
Value = $"Hello world!"
};
message.AddContent(content);
message.AddPersonalization(personalization);
mails.Add(message);
return null;
}
我使用这个源来构建我的示例: Azure Function SendGrid
推荐阅读
- python - Python 中浮点与十进制(定点)的规范
- python-3.x - Dynamo db 使用 Update_item 将不同的地图附加到列表中
- ruby-on-rails - Ruby on Rails 无法连接到 Docker 容器中的数据库主机
- django - Django 视图不向 ReactJS/Axios 应用程序发送上下文数据
- typescript - 如何创建添加黑名单用户或频道的不和谐机器人?
- python - 将多条图形线平均为一条,python 和 matplotlib
- node.js - 如何使用无服务器框架从另一个 lambda 异步调用 lambda
- c# - 如何为每个新线程创建新的类对象?
- blender - 在搅拌机 2.8 中更改线框背景
- android - 如何修复此 Kodein 错误:无法将表达式“kodein”作为函数调用。未找到函数“invoke()”