gpt4 book ai didi

c# - sendgrid向Azure功能中的多个收件人发送电子邮件失败

转载 作者:太空宇宙 更新时间:2023-11-03 14:54:47 24 4
gpt4 key购买 nike

(此问题的完整版本请参阅 https://social.msdn.microsoft.com/Forums/en-US/20bb5b37-82af-4cf3-8a59-04e5f19572bc/send-email-to-multiple-recipients-using-sendgrid-failure?forum=AzureFunctions )

发送给单个收件人已成功。但在Azure功能中找不到发送给多个收件人或CC/BCC的方法。

尝试了多种格式,包括

{ "to": [{ "email": ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d17121513531912183d18051c100d1118531e1210" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e7d6b606a697c676a7a6b7d7a6760694e69636f6762206d6163" rel="noreferrer noopener nofollow">[email protected]</a>" ] }] }

这似乎是azure功能的限制。但还不确定哪里出了问题。请参阅下面的“绑定(bind)”,

{

"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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d4c4f4e4d7e6c607d6168236e6260" rel="noreferrer noopener nofollow">[email protected]</a>",

"to": [{
"email": ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcbdacccb8effccded2cfd3da8e91dcd0d2" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15617066612755667478657970273b767a78" rel="noreferrer noopener nofollow">[email protected]</a>" ]
}]

}

],
"disabled": false

}

最佳答案

我使用 HTTP 触发器完成了示例,但在此基础上您将能够使其与服务总线触发器一起使用。

我的函数.json:

{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"type": "sendGrid",
"name": "mails",
"apiKey": "MySendGridKey",
"direction": "out",
"from":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75061418051910063513001b16011c1a1b065b161a18" rel="noreferrer noopener nofollow">[email protected]</a>"
}
],
"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("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="23454c4c634142510d404c4e" rel="noreferrer noopener nofollow">[email protected]</a>"));
personalization.AddTo(new Email("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a6c6565384a686b7824696567" rel="noreferrer noopener nofollow">[email protected]</a>"));
// 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

关于c# - sendgrid向Azure功能中的多个收件人发送电子邮件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50023458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com