use*_*254 2 javascript azure sendgrid azure-functions
我想使用 SendGrid 从 Azure 函数 (Javascript) 发送电子邮件。我做了以下事情
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);
};
Run Code Online (Sandbox Code Playgroud)
但电子邮件没有发送。请提供一些指示
我最初测试并遇到与你同样的问题。
请改为context.done(null, {message});
您可以尝试使用以下代码:
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});
};
Run Code Online (Sandbox Code Playgroud)
function.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
}
Run Code Online (Sandbox Code Playgroud)
这里我使用Gmail,所以我也允许不太安全的应用程序:ON
点击此链接,您可以进行配置。
| 归档时间: |
|
| 查看次数: |
2141 次 |
| 最近记录: |