从节点 AWS SDK(简单电子邮件服务)发送电子邮件时出现 SignatureDoesNotMatch 错误
SignatureDoesNotMatch error when sending an email from Node AWS SDK (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: ["REDACTED@REDACTED.com"]
},
Message: {
Subject: {
Charset: "UTF-8",
Data: "Test email"
},
Body: {
Text: {
Charset: "UTF-8",
Data: "This is the message body in text format."
}
}
},
Source: "REDACTED@REDACTED.com"
});
}
main().catch(console.error);
这段代码有问题吗?
谢谢
好的,我发现我的错误:我使用的是与用户一起生成的访问密钥,实际上是一个 SMTP login/password,而不是您可以在 SDK 中使用的访问密钥(即使它出现在 IAM 中的访问密钥下)。
解决方案是在 IAM 中创建一个新的访问密钥,然后我使用 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: "REDACTED@REDACTED.com",
to: "REDACTED@REDACTED.com",
subject: "Test email",
text: "This is the message body in text format."
});
}
main().catch(console.error);
我尝试在 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: ["REDACTED@REDACTED.com"]
},
Message: {
Subject: {
Charset: "UTF-8",
Data: "Test email"
},
Body: {
Text: {
Charset: "UTF-8",
Data: "This is the message body in text format."
}
}
},
Source: "REDACTED@REDACTED.com"
});
}
main().catch(console.error);
这段代码有问题吗?
谢谢
好的,我发现我的错误:我使用的是与用户一起生成的访问密钥,实际上是一个 SMTP login/password,而不是您可以在 SDK 中使用的访问密钥(即使它出现在 IAM 中的访问密钥下)。
解决方案是在 IAM 中创建一个新的访问密钥,然后我使用 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: "REDACTED@REDACTED.com",
to: "REDACTED@REDACTED.com",
subject: "Test email",
text: "This is the message body in text format."
});
}
main().catch(console.error);