簡體   English   中英

如何使用 node.js 動態設置 aws ses TemplateData?

[英]How to dynamically set aws ses TemplateData using node.js?

我正在嘗試發送帶有自定義數據的 email。

async function sendEmailToSalesTeamOnBookingDemoClass(email,name,phoneNumber,utmSource,utmTerm,utmMedium,deviceType,browser,referrer) {
  try {
      let emailMe = "abc@gmail.com"
      const ses = new AWS.SES({ apiVersion: "2010-12-01" });
      const params = {
        Destination: {
          ToAddresses: [emailMe]
        },
        Source: senderEmail,
        Template: "Sales_Email_Demo",
        TemplateData : JSON.stringify({
          "name": name,
          "email": email,
          "phone": phoneNumber,
          "utmSource":utmSource,
          "utmTerm":utmTerm,
           "utmMedium":utmMedium,
           "browser":browser,
           "referrer":referrer,
           "deviceType":deviceType
       }),
        Tags: [                                       
          {
            Name: 'SomeName',
            Value: 'info'
          }
        ]
      };
      const sendEmailReceiver = ses.sendTemplatedEmail(params).promise();
      sendEmailReceiver
        .then(data => {
          console.log(senderEmail,emailMe)
          console.log("Email submitted to SES", data);
        })
        .catch(error => {
          console.log("Email not submitted to SES:" + error);
        });
  }
  catch (e) {
    console.error(`Error: ${e}`);
  }
}

響應說 email 已成功發送。

Email submitted to SES {
  ResponseMetadata: { RequestId: 'c08b9948-7be3-465d-a72c-fcca23f9f059' },
  MessageId: '010901793bd95a02-813072dc-bb87-4b65-91c4-03f7f29dcbd0-000000'
}

但是,即使發送方 email 已經過驗證和測試,也沒有收到 email。 我的模板有問題嗎?

        {
        "Template": {
          "TemplateName": "Sales_Email_Demo",
          "SubjectPart": "some subject!",
          "HtmlPart": "<html> <body><p>Hello,</p><p>Details:</p><p>Name:{{name}}</p><p>Phone Number: {{phoneNumber}}</p><p>Email Id: {{emailId}}</p><p>Source: {{utmSource}}</p><p>Medium: {{utmMedium}}</p><p>Term:{{utmTerm}}</p><p>Device:{{deviceType}}</p><p>Browser:{{browser}}</p><p>Referrer: {{referrer}}</p></body></html>"
          }
        }

我想到了。 問題出在模板上。 發送和接收變量的名稱不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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