简体   繁体   中英

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

I'm trying to send an email with custom data.

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}`);
  }
}

The response says that the email was sent successfully.

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

But there is no email received even though the sender email has been verified and tested. Is there something wrong with my template?

        {
        "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>"
          }
        }

I figured it out. The issue was with the template. The sending and receiving variables were named differently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM