Nodemailer SES TRANSPORT错误:TypeError:this.ses.sendRawEmail不是函数

jobtbby3  于 2023-08-04  发布在  Node.js
关注(0)|答案(3)|浏览(95)

我正在尝试在nodemailer的帮助下配置AWS SES。
所以我在跟踪documentation
这是他们提供的代码,我测试过:

let nodemailer = require("nodemailer");
let aws = require("@aws-sdk/client-ses");

const ses = new aws.SES({
  apiVersion: "2010-12-01",
  region: "us-west-2",
});

// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
  SES: { ses, aws },
});

// send some mail
transporter.sendMail(
  {
    // These are obviously not the actual emails I am using
    from: "configured_aws_email",
    to: "recipient_email",
    subject: "Message",
    text: "I hope this message gets sent!",
    ses: {
      // optional extra arguments for SendRawEmail
      Tags: [
        {
          Name: "tag_name",
          Value: "tag_value",
        },
      ],
    },
  },
  (err, info) => {
    console.log(
      "🚀 ~ file: transactional-email-confiig.js ~ line 36 ~ err",
      err
    );
    console.log(
      "🚀 ~ file: transactional-email-confiig.js ~ line 41 ~ info.envelope",
      info.envelope
    );
    console.log(
      "🚀 ~ file: transactional-email-confiig.js ~ line 43 ~ info.messageId",
      info.messageId
    );
  }
);

字符串
以下是我安装的所需软件包的版本:
package.json

"@aws-sdk/client-ses": "^3.40.0",
"aws-sdk": "^2.1026.0",


我在.env文件中配置了AWS密钥:
.env

AWS_ACCESS_KEY_ID=***************
AWS_SECRET_ACCESS_KEY=*************


这是节点版本:
node -v

v15.8.0


我使用的AWS SES电子邮件地址已验证:
x1c 0d1x的数据
但是,我一直得到这个错误:

node_modules/nodemailer/lib/ses-transport/index.js:242
                this.ses.sendRawEmail(sesMessage, (err, data) => {
                         ^

TypeError: this.ses.sendRawEmail is not a function

eeq64g8w

eeq64g8w1#

对于那些使用import而不是require的用户,请检查是否使用以下命令:

`import aws from '@aws-sdk/client-ses';`
`import * as aws from '@aws-sdk/client-ses';`

字符串
如这里所述。

6rqinv9w

6rqinv9w2#

看起来@aws-sdk/client-ses接口没有sendRawEmail方法。
尝试安装旧的aws-sdk软件包:
npm i aws-sdk
然后用它来代替

const nodemailer = require("nodemailer");
const aws = require("aws-sdk");

const ses = new aws.SES({
  apiVersion: "2010-12-01",
  region: "us-west-2",
});

// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
  SES: { ses, aws },
});

字符串

mo49yndu

mo49yndu3#

我遇到的一种可能性是jest mocking和重构,我正在从sendEmail更改为sendRawEmail,并且还需要更新mock声明。

相关问题