AzureFunctions绑定到SendGrid

时间:2017-01-07 12:31:28

标签: 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键与主题和正文进行了硬编码。这是我的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完全访问权限。我错过了什么想法?

Larsi

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

通过 local.settings.json 在您的 AppSettings 和配置中添加“AzureWebJobsSendGridApiKey” -> 通过 Azure 门户的应用程序设置将起作用。