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.
# 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.
Testing
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).