0

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.

 {
  "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.

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

This is root directory host.json file

{
 "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.? Reference taken for configuration file https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid enter image description here

swapnil jain
  • 252
  • 1
  • 3
  • 22

1 Answers1

0

Looks like you don't have the binding extension installed. You could either

{
  "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 add package Microsoft.Azure.WebJobs.Extensions.SendGrid --version 3.0.0
PramodValavala
  • 6,026
  • 1
  • 11
  • 30