簡體   English   中英

使用Azure Azure函數使用SendGrid發送電子郵件

[英]Javascript Azure Function to send email using SendGrid

我想使用SendGrid從Azure函數(Javascript)發送電子郵件。 我做了以下

  1. 為SendGrid API密鑰創建了一個新的AppSettings
  2. Azure函數的SendGrid輸出綁定集
  3. 以下是我的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);
};

但是電子郵件沒有發送。 請提供一些指示

我最初會測試並面對相同的問題。

請更改為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM