Reputation: 75
I want to send emails from an Azure function (Javascript) using SendGrid. I have done the following
module.exports = function (context, myQueueItem) {
var message = {
"personalizations": [ { "to": [ { "email": "[email protected]" } ] } ],
from: { email: "[email protected]" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: myQueueItem
}]
};
context.done(null, message);
};
But email is not getting send. Please provide some pointers
Upvotes: 2
Views: 2251
Reputation: 20067
I test and face the same problem with you initially.
Please change to context.done(null, {message});
You could try to use the following code:
module.exports = function (context, order) {
context.log(order);
var message = {
"personalizations": [ { "to": [ { "email": "[email protected]" } ] } ],
from: { email: "[email protected]" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: order
}]
};
context.done(null, {message});
};
And the funtion.json file is:
{
"bindings": [
{
"type": "queueTrigger",
"name": "order",
"direction": "in",
"queueName": "samples-orders"
},
{
"type": "sendGrid",
"name": "message",
"direction": "out",
"apiKey": "mysendgridkey",
"from": "[email protected]",
"to": "[email protected]"
}
],
"disabled": false
}
Here I use the Gmail, so I also Allow less secure apps: ON
Click this link, you could configure it.
Upvotes: 5