Javascript Azure函数使用SendGrid发送电子邮件 [英] Javascript Azure Function to send email using SendGrid
本文介绍了Javascript Azure函数使用SendGrid发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用SendGrid从Azure函数(Javascript)发送电子邮件.我已经完成了以下
I want to send emails from an Azure function (Javascript) using SendGrid. I have done the following
- 为SendGrid API密钥创建了一个新的AppSettings
- Azure功能的SendGrid输出绑定集
- 以下是我的Azure功能
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.
请更改为 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});
};
funtion.json文件为:
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": "testfrom@gmail.com",
"to": "testto@gmail.com"
}
],
"disabled": false
}
我在这里使用Gmail,所以我也允许安全性较低的应用程序:打开
Here I use the Gmail, so I also Allow less secure apps: ON
点击此链接,即可对其进行配置.
Click this link, you could configure it.
这篇关于Javascript Azure函数使用SendGrid发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文