简体   繁体   English

如何使用 azure JavaScript ZC1C425268E68385D14AB5074C17ZA 发送 email?

[英]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 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});
};

This is the function.json file code.这是 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"
 }
]
}

This is root directory local.setting.json file.这是根目录 local.setting.json 文件。

 {
  "IsEncrypted": false,
  "Values": {
  "AzureWebJobsStorage": "",
  "FUNCTIONS_WORKER_RUNTIME": "node",
  "SENDGRID_API_KEY": "SG.O1pazBKvS5Ox4YExYCY...."
 }
}

This is root directory host.json file这是根目录 host.json 文件

{
 "version": "2.0",
 "extensions": {
  "sendGrid": {
    "from": "Azure Functions <samples@functions.com>"
   }
  }
 }

Following error i am getting in the console.以下错误我进入控制台。 Also, what is the correct way to send this email.?另外,发送此 email 的正确方法是什么? Reference taken for configuration file https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid参考配置文件https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid 在此处输入图像描述

Looks like you don't have the binding extension installed.看起来您没有安装绑定扩展。 You could either你也可以

  • Use Extension Bundles by updating your host.json to something like this通过将您的host.json更新为类似的内容来使用扩展包
{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  },
  "extensions": {
    "sendGrid": {
      "from": "Azure Functions <samples@functions.com>"
    }
  }
}
  • Install the function extension using the dotnet CLI (Would need .NET Core installed locally)使用dotnet CLI 安装 function 扩展(需要在本地安装.NET 核心
dotnet add package Microsoft.Azure.WebJobs.Extensions.SendGrid --version 3.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM