【问题标题】:AzureFunctions binding to SendGridAzureFunctions 绑定到 SendGrid
【发布时间】:2017-01-07 12:31:27
【问题描述】:

试图弄清楚如何从一个 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 键。这是我的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": "me@gmail.com",
  "from": "me@gmail.no",
  "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

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

拉西

【问题讨论】:

    标签: azure sendgrid azure-functions


    【解决方案1】:

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

    【讨论】:

    • 是的,这会让人们大吃一惊。我们这样做是出于安全目的,将秘密值排除在您的源代码文件之外。我在我们的仓库中记录了一个问题,以便我们在这些情况下改进错误消息:github.com/Azure/azure-webjobs-sdk/issues/965.
    【解决方案2】:

    通过 local.settings.json 在您的 AppSettings 中添加“AzureWebJobsSendGridApiKey”,并在 Configuration -> Application Setting 中通过 Azure Portal 添加。

    【讨论】:

      猜你喜欢
      • 2018-10-28
      • 2016-08-29
      • 1970-01-01
      • 2022-10-19
      • 2019-12-15
      • 2021-04-08
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多