【问题标题】:How to send email using azure JavaScript function?如何使用 azure JavaScript 函数发送电子邮件?
【发布时间】:2019-10-18 11:28:43
【问题描述】:

它是我的 index.js 文件代码。我从这个链接 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>"
   }
  }
 }

我在控制台中遇到以下错误。另外,发送这封电子邮件的正确方法是什么?参考配置文件https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid

【问题讨论】:

    标签: javascript node.js azure azure-functions azure-node-sdk


    【解决方案1】:

    您似乎没有安装绑定扩展。你也可以

    {
      "version": "2.0",
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
      },
      "extensions": {
        "sendGrid": {
          "from": "Azure Functions <samples@functions.com>"
        }
      }
    }
    
    • 使用dotnet CLI 安装功能扩展(需要在本地安装.NET Core
    dotnet add package Microsoft.Azure.WebJobs.Extensions.SendGrid --version 3.0.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-02
      • 2022-12-03
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      相关资源
      最近更新 更多