简体   繁体   中英

ses.sendCustomVerificationEmail is not a function using AWS JavaScript SDK v2

I'm trying to use AWS SES API to verify emails in an a Nodejs/Express app that I'm putting together, and I'm trying to use a custom template for the verification email rather than the default one sent by Amazon to eliminate confusion as I don't want my users to receive an email saying "Dear Amazon Web Services Customer, We have received a request to authorize this email address for use with Amazon SES.... etc" and it seems simple enough according to AWS Docs here: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-verify-address-custom.html https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendCustomVerificationEmail-property

however when I try it I keep getting this error "ses.sendCustomVerificationEmail is not a function"

Can anyone tell me where I'm going wrong with this and maybe point me at the right direction.... Here is my code:

const express = require("express");
const aws = require("aws-sdk");
require("dotenv").config();

const app = express();

aws.config.update({
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  region: process.env.region
});

// Instantiate SES.
const ses = new aws.SES();

// Verify email addresses.
app.get("/verify/:email", (req, res) => {
  const params = {
    EmailAddress: req.params.email,
    TemplateName: "SampleTemplate" // template is already created
  };

  ses.sendCustomVerificationEmail(params, (err, data) => {
    if (err) {
      res.send(err);
    } else {
      res.send(data);
    }
  });
});


// Start server.
const server = app.listen(8000, () => {
  const port = server.address().port;

  console.log("AWS SES example app listening on port", port);
});

Thank you!!

This error will occur usually due to an outdated version of aws-sdk being installed by your package manager. In your case, you've been working on v2.1.35, which is severely out of date. When you update to the latest version of AWS JavaScript SDK v2, which is v2.973.0, you'll see the method that was previously missing is now available for use in the aws.SES namespace.

You should also consider migrating your code to the AWS JavaScript SDK v3 , as it has been superseding the v2 version of the SDK for quite some time now.

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