我正在尝试从运行在 EC2 机器上的 NodeJS 应用程序发送电子邮件,但我收到了一个我没想到的 访问被拒绝错误 。我遵循了这个 documentation,现在我的场景是(真实域、地址和 ID 已更改):
example.com
域在 us-east-1
区域中经过验证和配置,以在 AWS SES 中发送电子邮件。仍处于沙盒模式,以防万一my@email.com
地址已验证,因此我可以向其发送电子邮件。我可以使用 AWS 控制台将电子邮件从 noreply@example.com
发送到 my@email.com
。 MyEC2MachineRole
附加了以下策略,因此它只能使用 example.com
域发送电子邮件。此策略类似于 example in the docs (除了缺少 Principal
):{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ses:SendEmail",
"ses:SendRawEmail"
],
"Resource": "arn:aws:ses:us-east-1:111111111111:identity/example.com"
}
]
}
当我尝试运行以下代码时,基于 SDK documentation :
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' });
async function main() {
try {
const client = new AWS.SES({ apiVersion: '2010-12-01' });
const result = await client.sendEmail({
Destination: {
ToAddresses: ['my@email.com']
},
Message: {
Body: {
Text: {
Charset: 'UTF-8',
Data: 'Test',
},
},
Subject: {
Charset: 'UTF-8',
Data: 'Test e-mail',
},
},
Source: 'noreply@example.com'
}).promise();
console.log('Sent', result);
} catch (err) {
console.error('Error', err);
}
}
main();
我收到以下错误:
User
arn:aws:sts::111111111111:assumed-role/MyEC2MachineRole/i-0123456789abcdefg
is not authorized to performses:SendEmail
on resourcearn:aws:ses:us-east-1:111111111111:identity/my@email.com
如果我将目标地址更改为
example.com
域下的任何其他电子邮件,它就可以工作。如果我将策略上的 Resource
更改为 *
,它也会起作用。Resource
不是发送电子邮件的地址/域吗?为什么它试图对与目标地址相关的资源进行操作?这是否与此 AWS SES 配置仍处于沙盒模式有关?
最佳答案
现在帐户不在沙箱中,错误停止发生。在沙箱中,它可能需要额外的权限来发送电子邮件,例如对目标资源进行操作的权限。
关于node.js - 无法使用 AWS SES : didn't I configure it properly? 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55250973/