GetSimpl / amqp_mailer

Adds a new action mailer delivery method - amqp
MIT License
0 stars 0 forks source link

AmqpMailer

This gem provides an easy way to send emails using notifications service.

Installation

Add this line to your application's Gemfile:

gem 'amqp_mailer', git: 'https://github.com/GetSimpl/amqp_mailer.git', tag: '<use latest>'

And then execute:

$ bundle

Usage

Change action mailer's delivery method to :amqp

config.action_mailer.delivery_method = :amqp

Configure AmqpMailer by setting required parameters

AmqpMailer.configure do |config|
  config.amqp_url = ENV['AMQP_URL']
  config.notifications_topic_exchange = ENV['NOTIFICATIONS_TOPIC_EXCHANGE']
  config.service_id = 'monsters-inc'
end

Pass phone number in addition to other parameters to mail() method of ActionMailer

mail(to: 'woody@pixar.com', subject: 'To Infinity and Beyond', 'X-SIMPL-USER-ID': user_id, 'X-SIMPL-PHONE-NUMBER': phone_number)

To send mail with attachment, upload the file to S3 bucket and send the bucket name and object key in mail attachment attributes as JSON

mail(to: 'woody@pixar.com', subject: 'To Infinity and Beyond', 'X-SIMPL-USER-ID': user_id, 'X-SIMPL-PHONE-NUMBER': phone_number, attachments: [{bucket_id: "bucket_name", object_key: "object_key"}].to_json)

Gotcha

This doesn't support multipart emails (yet). That is if you have both <template>.html.erb and <template>.text.erb, remove <template>.text.erb.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Some useful resources:

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/GetSimpl/amqp_mailer.

License

The gem is available as open source under the terms of the MIT License.