You will have to ensure that you provide credentials for the SDK to use. See the
latest AWS SDK for Ruby Docs
for details.
If you’re running your Rails application on Amazon EC2, the AWS SDK will
check Amazon EC2 instance metadata for credentials to load. Learn more:
IAM Roles for Amazon EC2
SNS Subscriptions will now be auto-confirmed and messages will be automatically
handled via ActionMailbox.
Note: Even if you manually confirm subscriptions, you will still need to provide
a list of subscribed topics; messages from unrecognized topics will be ignored.
Decrypting client-side-encrypted objects (SES with KMS)
If config.action_mailbox.ses.s3_client is not set, the gem uses the default
plain Aws::S3::Client — identical to the pre-0.1.2 behavior. The settings
below only kick in when you configure a custom client.
When the SES receipt rule specifies a KMS key on its S3 action, SES uses the
Amazon S3 encryption client
to client-side-encrypt the email body with AES-GCM before upload. Plain
Aws::S3::Client.get_object returns the ciphertext unchanged — Mail can’t
parse it. Configure a pre-built encryption client:
Set SES_INBOUND_CMK_ARN to the ARN of your AWS KMS key.
Mixed buckets (encrypted + unencrypted objects)
If your bucket holds both encrypted and unencrypted objects (e.g. during a
migration window or when re-driving older mail), opt into per-object routing:
When enabled, the gem issues a HEAD probe before each fetch and picks the
plain client for objects that lack x-amz-key-v2 / x-amz-key metadata.
Off by default.
AWS IAM policy requirements:
s3:GetObject on the bucket
kms:Decrypt on the CMK SES used to encrypt
s3:HeadObject if decrypt_fallback_to_plain = true
Testing
Two RSpecrequest spec helpers are provided to facilitate testing
Amazon SNS/SES notifications in your application:
# spec/requests/amazon_emails_spec.rb
RSpec.describe 'amazon emails', type: :request do
it 'delivers a subscription notification' do
action_mailbox_ses_deliver_subscription_confirmation
expect(response).to have_http_status :ok
end
it 'delivers an email notification' do
action_mailbox_ses_deliver_email(mail: Mail.new(to: 'user@example.com'))
expect(ActionMailbox::InboundEmail.last.mail.recipients).to eql ['user@example.com']
end
end
You may also pass the following keyword arguments to both helpers:
topic: The SNS topic used for each notification (default: topic:arn:default).
authentic: The Aws::SNS::MessageVerifier class is stubbed by these helpers;
set authentic to true or false to define how it will verify
incoming notifications (default: true).
Amazon Simple Email Service (SES) as an ActionMailbox Ingress
This gem contains an ActionMailbox ingress using Amazon SES, SNS, and S3.
Installation
Add this gem to your Rails project’s Gemfile:
Then run
bundle install.This gem also brings in the following AWS gems:
aws-sdk-s3aws-sdk-snsYou will have to ensure that you provide credentials for the SDK to use. See the latest AWS SDK for Ruby Docs for details.
If you’re running your Rails application on Amazon EC2, the AWS SDK will check Amazon EC2 instance metadata for credentials to load. Learn more: IAM Roles for Amazon EC2
Configuration
Amazon SES/SNS
Configure SES to save emails to S3 or to send them as raw messages.
Configure the SNS topic for SES or for the S3 action to send notifications to +/rails/action_mailbox/ses/inbound_emails+. For example, if your website is hosted at https://www.example.com then configure SNS to publish the SES notification topic to this HTTP endpoint: https://example.com/rails/action_mailbox/ses/inbound_emails
Rails
Configure ActionMailbox to accept emails from Amazon SES:
Configure which SNS topic will be accepted and what region.
Note: The bucket’s region, which stores the emails, does not need to match the SNS topic’s region.
SNS Subscriptions will now be auto-confirmed and messages will be automatically handled via ActionMailbox.
Note: Even if you manually confirm subscriptions, you will still need to provide a list of subscribed topics; messages from unrecognized topics will be ignored.
See ActionMailbox documentation for full usage information.
Decrypting client-side-encrypted objects (SES with KMS)
If
config.action_mailbox.ses.s3_clientis not set, the gem uses the default plainAws::S3::Client— identical to the pre-0.1.2 behavior. The settings below only kick in when you configure a custom client.When the SES receipt rule specifies a KMS key on its S3 action, SES uses the Amazon S3 encryption client to client-side-encrypt the email body with AES-GCM before upload. Plain
Aws::S3::Client.get_objectreturns the ciphertext unchanged —Mailcan’t parse it. Configure a pre-built encryption client:Set
SES_INBOUND_CMK_ARNto the ARN of your AWS KMS key.Mixed buckets (encrypted + unencrypted objects)
If your bucket holds both encrypted and unencrypted objects (e.g. during a migration window or when re-driving older mail), opt into per-object routing:
When enabled, the gem issues a HEAD probe before each fetch and picks the plain client for objects that lack
x-amz-key-v2/x-amz-keymetadata. Off by default.AWS IAM policy requirements:
s3:GetObjecton the bucketkms:Decrypton the CMK SES used to encrypts3:HeadObjectifdecrypt_fallback_to_plain = trueTesting
Two RSpec request spec helpers are provided to facilitate testing Amazon SNS/SES notifications in your application:
action_mailbox_ses_deliver_subscription_confirmationaction_mailbox_ses_deliver_emailInclude the
Aws::ActionMailbox::SES::RSpecextension in your tests:Configure your test environment to accept the default topic used by the provided helpers:
Example Usage
You may also pass the following keyword arguments to both helpers:
topic: The SNS topic used for each notification (default:topic:arn:default).authentic: TheAws::SNS::MessageVerifierclass is stubbed by these helpers; setauthentictotrueorfalseto define how it will verify incoming notifications (default:true).