- Rails plugin containing delivery_method, generators, capistrano recipies
- worker daemon fetching mails for queue and doing the final delivery using two methods: base and emergency, if base delivery fails, then emergency is being used.
Add mongo_mailer to your Gemfile
:
gem 'mongo_mailer', require: 'mongo_mailer/rails'
Run the generator:
bundle exec rails generate mongo_mailer
which creates config/mongo_mailer.yml.example
Based on example configuration file, create mongo_mailer.yml
and add it to gitignored.
mongo_mailer.yml
contains configuration of mongo database and final delivery methods used by worker.
Set ActionMailer::Base
delivery method in your environment file:
config.action_mailer.delivery_method :mongo_queue
Add mongo_mailer capistrano recipies, by adding:
require 'mongo_mailer/capistrano'
to your deploy.rb
. Since then you have access to cap mongo_mailer:start|stop|restart
recipies.
Worker can be used within a rails app or as a standalone application. In both cases only mongo_mailer related stuff is used - rails are never being loaded.
Worker usees daemons to daemonize the process, continuously polls mongo queue for new mail and does the final delivery.
- to start, stop or restart worker just run:
bundle exec mongo_mailer start|stop|restart [rails_env]
within a rails app, or:
bundle exec worker start|stop|restart [app_env]
in a standalone version.
- by default workers activity and pids are being loged in the app's
log
directory:
log/mongo_mailer.output log/mongo_mailer.log log/mongo_mailer.pid
you can change it, by modifying proper daemon options in mongo_mailer.yml
.
- all sent mail are logged into:
log/mongo_queue.log
mongo_mailer doesn't have any web interface, so irb console is the only interface to get information :)
MongoMailer::DeliveriesCounter.instance.by_type(:base) => {"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11} MongoMailer::DeliveriesCounter.instance.by_type(:emergency) => {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:base, "value"=>1} MongoMailer::DeliveriesCounter.instance.all => [{"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11}, {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:emergency, "value"=>1}]
MongoMailer::MailQueue.instance.invalid_items
MongoMailer::MailQueue.instance.clear_invalid_items!
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request