Provides Amazon SES/SNS integration with Rails ActionMailbox.
Add this line to your application's Gemfile:
gem 'action_mailbox_amazon_ingress', '~> 0.1.0'
Configure SES to route emails through SNS.
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/amazon/inbound_emails
Configure ActionMailbox to accept emails from Amazon SES:
# config/environments/production.rb
config.action_mailbox.ingress = :amazon
Configure which SNS topics will be accepted:
# config/environments/production.rb
config.action_mailbox.amazon.subscribed_topics = %w(
arn:aws:sns:eu-west-1:123456789001:example-topic-1
arn:aws:sns:us-east-1:123456789002:example-topic-2
)
Subscriptions will now be auto-confirmed and messages will be delivered via ActionMailbox.
Note that 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.
Two RSpec request spec helpers are provided to facilitate testing Amazon SNS/SES notifications in your application:
amazon_ingress_deliver_subscription_confirmation
amazon_ingress_deliver_email
Include the ActionMailboxAmazonIngress::RSpec
extension in your tests:
# spec/rails_helper.rb
require 'action_mailbox_amazon_ingress/rspec'
RSpec.configure do |config|
config.include ActionMailboxAmazonIngress::RSpec
end
Configure your test environment to accept the default topic used by the provided helpers:
# config/environments/test.rb
config.action_mailbox.amazon.subscribed_topics = ['topic:arn:default']
# spec/requests/amazon_emails_spec.rb
RSpec.describe 'amazon emails', type: :request do
it 'delivers a subscription notification' do
amazon_ingress_deliver_subscription_confirmation
expect(response).to have_http_status :ok
end
it 'delivers an email notification' do
amazon_ingress_deliver_email(mail: Mail.new(to: '[email protected]'))
expect(ActionMailbox::InboundEmail.last.mail.recipients).to eql ['[email protected]']
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
: TheAws::SNS::MessageVerifier
class is stubbed by these helpers; setauthentic
totrue
orfalse
to define how it will verify incoming notifications (default:true
).
Ensure Rubocop, RSpec, and StrongVersions compliance by running make
:
make
Pull requests are welcome.
The gem is available as open source under the terms of the MIT License.