[英]Javascript Azure Function to send email using SendGrid
I want to send emails from an Azure function (Javascript) using SendGrid. 我想使用SendGrid从Azure函数(Javascript)发送电子邮件。 I have done the following
我做了以下
module.exports = function (context, myQueueItem) {
var message = {
"personalizations": [ { "to": [ { "email": "testto@test.com" } ] } ],
from: { email: "testfrom@test.com" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: myQueueItem
}]
};
context.done(null, message);
};
But email is not getting send. 但是电子邮件没有发送。 Please provide some pointers
请提供一些指示
I test and face the same problem with you initially. 我最初会测试并面对相同的问题。
Please change to context.done(null, {message}); 请更改为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": "testto@gmail.com" } ] } ],
from: { email: "testfrom@gmail.com" },
subject: "Azure news",
content: [{
type: 'text/plain',
value: order
}]
};
context.done(null, {message});
};
And the funtion.json file is: 并且funtion.json文件是:
{
"bindings": [
{
"type": "queueTrigger",
"name": "order",
"direction": "in",
"queueName": "samples-orders"
},
{
"type": "sendGrid",
"name": "message",
"direction": "out",
"apiKey": "mysendgridkey",
"from": "testfrom@gmail.com",
"to": "testto@gmail.com"
}
],
"disabled": false
}
Here I use the Gmail, so I also Allow less secure apps: ON 我在这里使用Gmail,因此我也允许安全性较低的应用程序:开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.