javascript - 从 Node AWS SDK(简单电子邮件服务)发送电子邮件时出现 SignatureDoesNotMatch 错误

标签 javascript node.js amazon-web-services amazon-simple-email-service

我尝试使用 Node 中的 @aws-sdk/client-ses SDK 发送电子邮件,但我得到:

SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

这是我的代码:

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

async function main() {
  const ses = new aws.SES({
    region: "eu-west-3",
    credentials: {
      accessKeyId: "REDACTED",
      secretAccessKey: "REDACTED"
    }
  });
  await ses.sendEmail({
    Destination: {
      ToAddresses: ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1547505154564150515547505154564150513b767a78" rel="noreferrer noopener nofollow">[email protected]</a>"]
    },
    Message: {
      Subject: {
        Charset: "UTF-8",
        Data: "Test email"
      },
      Body: {
        Text: {
          Charset: "UTF-8",
          Data: "This is the message body in text format."
        }
      }
    },
    Source: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9dcfd8d9dcdec9d8d9ddcfd8d9dcdec9d8d9b3fef2f0" rel="noreferrer noopener nofollow">[email protected]</a>"
  });
}

main().catch(console.error);

这段代码有问题吗?

谢谢

最佳答案

好吧,我发现了我的错误:我使用的是用户生成的访问 key ,这实际上是 SMTP 登录名/密码,而不是您可以在 SDK 中使用的访问 key (即使它出现在IAM)。

解决方案是在 IAM 中创建一个新的访问 key ,然后我使用 nodemailer (因为否则我的代码使用操作 ses:SendEmail 而不是 ses :SendRawEmail)

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

async function main() {
  let transporter = nodemailer.createTransport({
    SES: {
      ses: new aws.SES({
        region: "eu-west-3",
        credentials: {
          accessKeyId: "REDACTED",
          secretAccessKey: "REDACTED"
        }
      }),
      aws
    }
  });
  await transporter.sendMail({
    from: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94c6d1d0d5d7c0d1d0d4c6d1d0d5d7c0d1d0baf7fbf9" rel="noreferrer noopener nofollow">[email protected]</a>",
    to: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d7f68696c6e7968696d7f68696c6e796869034e4240" rel="noreferrer noopener nofollow">[email protected]</a>",
    subject: "Test email",
    text: "This is the message body in text format."
  });
}

main().catch(console.error);

关于javascript - 从 Node AWS SDK(简单电子邮件服务)发送电子邮件时出现 SignatureDoesNotMatch 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68443435/

相关文章:

python - 如何在 aws EC2 实例(ubuntu)上运行 python 脚本?

javascript - 如何同步客户端和服务器上的socketIO连接ID?

node.js - 在 SSR 上的 react 组件中导入 scss

node.js - Node.js 的版本控制工具

html - 具有相同名称的多个输入的nodejs表单

amazon-web-services - 有没有办法将 AWS IAM 与 LDAP 服务器连接起来?

node.js - AWS Lambda 函数子目录中的处理程序未运行

javascript - 从 HTML 复制的电子邮件在 Thunderbird 中不起作用

Javascript 异常隐藏在 Promises 中。我怎样才能在没有捕获的情况下显示它们?

javascript - 如何使用 jQuery 停止动画