![](/img/trans.png)
[英]How to send email using azure JavaScript function?
[英]Javascript Azure Function to send email using SendGrid
我想使用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);
};
但是電子郵件沒有發送。 請提供一些指示
我最初會測試並面對相同的問題。
請更改為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});
};
並且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
}
我在這里使用Gmail,因此我也允許安全性較低的應用程序:開
單擊此鏈接 ,可以對其進行配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.