我尝试使用 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/