【发布时间】:2020-10-08 16:58:39
【问题描述】:
我试图了解我应该如何在 Azure 门户中开发的 Azure 函数中使用 SendGrid。正如 Google 所建议的那样,我一直在从多个角度进行研究,但似乎有许多过时的方法,我无法通过 Azure 门户中可用的方法来解决。下面是我当前发送电子邮件的基本迭代,我直接从 SendGrid 博客 (https://sendgrid.com/blog/using-sendgrid-with-azure-functions-to-send-mobile-app-survey-data) 中提取。我已经看到使用 project.json 文件来确保安装 SendGrid 包的引用,但我无法在我的函数中创建这样的文件,我只能操作 run .csx 和 function.json 文件。下面是我的代码和我遇到的错误。我错过了什么?
#r "Newtonsoft.Json"
#r "SendGrid"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using SendGrid.Helpers.Mail;
public static void Run(HttpRequest req, ILogger log, out Message message)
{
log.LogInformation("C# HTTP trigger function processed a request.");
message = new Mail {
Subject = "Test Notification"
};
string requestBody = new StreamReader(req.Body).ReadToEnd();
Content content = new Content {
Type = "text/html",
Value = requestBody
};
message.AddContent(content);
}
错误:
[错误] run.csx(10,58):错误 CS0246:找不到类型或命名空间名称“消息”(您是否缺少 using 指令或程序集引用?)
[错误] run.csx(14,19):错误 CS0246:找不到类型或命名空间名称“邮件”(您是否缺少 using 指令或程序集引用?)
【问题讨论】:
标签: azure azure-functions sendgrid azure-function-app