node.js - 无法使用 AWS SES : didn't I configure it properly? 发送电子邮件

标签 node.js amazon-web-services email aws-sdk amazon-ses

我正在尝试从运行在 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 perform ses:SendEmail on resource arn: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/

    相关文章:

    c# - 使用 System.Net.Mail 加速通过 smtp 服务器发送多封电子邮件

    c# - C# 中的 AWS DynamoDb 事务

    javascript - 如何使用 Puppeteer 覆盖 native 功能

    ios - Flutter ios 设备不会从 FCM 通知触发 onMessage。实现 APN 时 Sendtodevice 失败

    node.js - 当客户端刷新或打开新页面时,Socket.io 在客户端保持连接

    自动缩放服务器上的 PHP session

    amazon-web-services - 如何仅列出实例 ID 和相关标签

    php - 将结果从随机数组发送到电子邮件 php

    c# - 如何在C#中单击按钮并打开窗口发送电子邮件

    node.js - 如何验证字段是电子邮件还是用户名