简体   繁体   English

如果没有针对所有域的 IAM 策略设置,则无法使用 AWS SES 和 Rails 的 Action Mailer 发送电子邮件

[英]Cannot send emails using AWS SES and Rails' Action Mailer without IAM Policy settings for all domains

I want to send emails using AWS SES via Action Mailer in Ruby on Rails (v6).我想使用 AWS SES 通过 Ruby on Rails (v6) 中的 Action Mailer 发送电子邮件。 AWS provides aws-sdk-rails gem, and it makes to be easy to configure using SES, but I realized that it needs sendable permissions such as ses:SendEmail to ALL domains in SES. AWS 提供了aws-sdk-rails gem,它使得使用 SES 配置变得容易,但我意识到它需要可发送权限,例如ses:SendEmail到 SES 中的所有域。

# config/initializers/aws-sdk.rb
Aws.config[:credentials] = Aws::Credentials.new(ENV["AWS_ACCESS_KEY_ID"], ENV["AWS_SECRET_ACCESS_KEY"])

Aws::Rails.add_action_mailer_delivery_method(:aws_sdk, region: "us-east-1")
Rails.application.config.action_mailer.delivery_method = :aws_sdk
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
  default from: "info@example.com"
end

An AWS IAM User has the following policy, which allows to send emails from only example.com domain. AWS IAM 用户具有以下策略,仅允许从example.com域发送电子邮件。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "ses:SendEmail",
        "ses:SendRawEmail"
      ],
      "Resource": [
        "arn:aws:ses:us-east-1:xxxxxxxxxxxx:identity/example.com"
      ],
      "Effect": "Allow"
    }
  ]
}

But I got an error like the following when workers send emails.但是当工作人员发送电子邮件时,我收到了如下错误。

ERROR: Processor failed: User `arn:aws:iam::xxxxxxxxxxxx:user/my-group/my-iam-user' is not authorized to perform `ses:SendRawEmail' on resource `arn:aws:ses:us-east-1:xxxxxxxxxxxx:identity/other-domain.com'

I think the SDK verifies whether all domains have sendable permissions by default, but I couldn't find to specify a target domain.我认为 SDK 默认会验证是否所有域都具有可发送权限,但我找不到指定目标域。 What should I do?我应该怎么办?

This is caused as a result of the domain being in a sandbox account.这是由于域位于沙盒帐户中造成的。 Within the SES documentation the following states are identified:SES 文档中,确定了以下状态:

  • You can only send mail to verified email addresses and domains, or to the Amazon SES mailbox simulator.您只能将邮件发送到经过验证的 email 地址和域,或者发送到 Amazon SES 邮箱模拟器。
  • You can only send mail from verified email addresses and domains.您只能从经过验证的 email 地址和域发送邮件。

To send emails to any email address you need to move your from domain(s) out of sandbox mode .要将电子邮件发送任何 email 地址,您需要将您的域移出沙盒模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM