它是我的 index.js 文件代码。我从这个链接Javascript Azure 函数中引用了使用 SendGrid 发送电子邮件
module.exports = async function (context, req) {
var message = {
"personalizations": [ { "to": [ { "email": "testto@gmail.com" } ] } ],
from: { email: "testfrom@gmail.com" },
subject: "Azure news",
content: [{
type: 'application/json',
value: req.body.to
}]
};
context.done(null, {message});
};
这是 function.json 文件代码。
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "sendGrid",
"direction": "out",
"apiKey" : "SG.O1pazBKvS5Ox4YExYCY...",
"to": "df@mail.com ",
"from": "gh@gmail.com",
"subject": "SendGrid output bindings"
}
]
}
这是根目录 local.setting.json 文件。
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"SENDGRID_API_KEY": "SG.O1pazBKvS5Ox4YExYCY...."
}
}
这是根目录 host.json 文件
{
"version": "2.0",
"extensions": {
"sendGrid": {
"from": "Azure Functions <samples@functions.com>"
}
}
}
以下错误我进入控制台。另外,发送这封电子邮件的正确方法是什么?参考配置文件https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid