[英]How to send email using azure JavaScript function?
its my index.js file code.which i have taken a refrence from this link Javascript Azure Function to send email using 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>"
}
}
}
以下错误我进入控制台。 另外,发送此 email 的正确方法是什么? 参考配置文件https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid
看起来您没有安装绑定扩展。 你也可以
host.json
更新为类似的内容来使用扩展包{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"extensions": {
"sendGrid": {
"from": "Azure Functions <samples@functions.com>"
}
}
}
dotnet
CLI 安装 function 扩展(需要在本地安装.NET 核心)dotnet add package Microsoft.Azure.WebJobs.Extensions.SendGrid --version 3.0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.