AzureFunctions 绑定(bind)到 SendGrid

标签 azure sendgrid azure-functions

尝试弄清楚如何从 azure 函数使用 SendGrid。没有太多文档可找到,但这是我尝试过的:

#r "SendGrid"
using SendGrid.Helpers.Mail;
using System;

public static void Run(string myQueueItem, out Mail message, TraceWriter log)
{
    log.Info($"C# Queue trigger function processed: {myQueueItem}");
    message=new Mail();
}

我已经对主题和正文以及集成输出部分中的 api key 进行了硬编码。这是我的 function.json:

{
"bindings": [
{
  "name": "myQueueItem",
  "type": "queueTrigger",
  "direction": "in",
  "queueName": "send-email-request",
  "connection": "myStorage"
},
{
  "type": "sendGrid",
  "name": "message",
  "apiKey": "SG.xxxxxxxxxxx",
  "direction": "out",
  "to": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfd2daffd8d2ded6d391dcd0d2" rel="noreferrer noopener nofollow">[email protected]</a>",
  "from": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d5ddf8dfd5d9d1d496d6d7" rel="noreferrer noopener nofollow">[email protected]</a>",
  "subject": "hardcoded",
  "text": "test213"
}
],
"disabled": false
}

我收到以下错误:

Function ($SendEmailOnQueueTriggered) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.SendEmailOnQueueTriggered'. Microsoft.Azure.WebJobs.Host: 'SG.xxxxxx' does not resolve to a value.
Session Id: 9426f2d7e4374c7ba7e0612ea5dc1814
Timestamp: 2017-01-07T12:18:01.930Z

我已授予 Apkey 在 SendGrid 中的完全访问权限。我错过了什么想法吗?

拉尔西

最佳答案

ApiKey 字段不是实际的 ApiKey,它应该是“功能应用程序设置”中定义的 AppSettings 键的名称。

关于AzureFunctions 绑定(bind)到 SendGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41521465/

相关文章:

azure - 在azure docker VM中运行docker命令

azure-web-app-service - 从 azure-cli 向 Web App 或 Function App 添加 App Insights 支持

azure - 使用服务总线触发器横向扩展 Function App

python - Microsoft-Graph : Failing to get token from python code: Error SSLError(SSLCertVerificationError(1, '[SSL:CERTIFICATE_VERIFY_FAILED]

azure - 我可以通过使用测试程序集在构建管道中执行自动化测试来更新测试计划吗

azure - 通过 REST API 刷新 Azure VM 的 IP 地址

azure-ad-b2c - 来自自定义策略的 SendGrid API 发送没有主题的电子邮件

c# - 等待来自 SendGrid 的 API 返回代码时应用程序卡住

firebase - 由于 CNAME 中的下划线,无法使用 Google 域设置 SendGrid

Azure 函数在本地工作,但上传到 azure 后不起作用