AzureFunctions 绑定到 SendGrid

Lar*_*rsi 1 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();
}
Run Code Online (Sandbox Code Playgroud)

我已经对主题和正文以及集成输出部分中的 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
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我已在 SendGrid 中授予 Apikey 完全访问权限。任何想法我错过了什么?

拉西

Lar*_*rsi 5

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

  • 是的,这让人们很兴奋。我们这样做是出于安全目的,将秘密值保留在您的源代码文件之外。我在我们的 repo 中记录了一个问题,以便我们改进这些情况下的错误消息:https://github.com/Azure/azure-webjobs-sdk/issues/965。 (2认同)