本文介绍了Javascript Azure函数使用SendGrid发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为SendGrid API密钥创建了一个新的AppSettings Azure功能的SendGrid输出绑定集 以下是我的Azure功能
我想使用SendGrid从Azure函数(Javascript)发送电子邮件.我已经完成了以下
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": "testto@test" } ] } ], from: { email: "testfrom@test" }, 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" } ] } ], from: { email: "testfrom@gmail" }, 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", "to": "testto@gmail" } ], "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发送电子邮件
发布评论