Simple email tracker for Ruby on Rails applications. Emailbutler allows you to track delivery status of emails sent by your app through Sendgrid, SMTP2GO, Resend, Mailjet.
There are situations when you need to check whether a certain letter or certain type of letters was successfully sent from the application, and through the UI of some providers you can try to find such a letter by the recipient or the subject of the letter, but sometimes it's not enough.
Emailbutler allows you to monitor the sending of letters, collects notifications from providers about the success of delivery and adds an UI for monitoring deliveries with filtering by recipients, mailers and actions.
Add this line to your application's Gemfile:
gem 'emailbutler'
gem 'pagy'
And then execute:
$ bundle install
$ rails g emailbutler:active_record
$ rails db:migrate
Add configuration line to config/initializers/emailbutler.rb:
require 'emailbutler/adapters/active_record'
Emailbutler.configure do |config|
config.adapter = Emailbutler::Adapters::ActiveRecord.new # required
config.providers = %w[sendgrid smtp2go resend mailjet mailtrap mandrill] # optional
config.ui_username = 'username' # optional
config.ui_password = 'password' # optional
config.ui_secured_environments = ['production'] # optional
end
Add this line to config/routes.rb
mount Emailbutler::Engine => '/emailbutler'
If you need some custom behaviour you can specify your own route and use custom controller, something like
class SendgridController < ApplicationController
skip_before_action :basic_authentication
skip_before_action :verify_authenticity_token
def create
... you can add some logic here
Emailbutler::Container.resolve(:webhooks_receiver).call(
mapper: Emailbutler::Container.resolve(:sendgrid_mapper),
payload: receiver_params
)
head :ok
end
private
def receiver_params
params.permit('event', 'sendtime', 'message-id').to_h
end
end
Update you application mailer
class ApplicationMailer < ActionMailer::Base
include Emailbutler::Mailers::Helpers
end
- go to Mail settings,
- turn on Event Webhook,
- in the HTTP POST URL field, paste the URL to webhook controller of your app (host/emailbutler/webhooks/sendgrid),
- select all deliverability data,
- save settings.
- go to Mail settings,
- turn on Webhooks,
- in the HTTP POST URL field, paste the URL to webhook controller of your app (host/emailbutler/webhooks/smtp2go),
- select all deliverability data,
- save settings.
- go to Mail settings,
- add Webhook,
- in the Endpoint URL field, paste the URL to webhook controller of your app (host/emailbutler/webhooks/resend),
- select all deliverability data,
- save settings.
- Each event with sending email will create new record with message params in database.
- Each webhook event will update status of message in database.
Emailbutler provides UI with rendering email tracking statistics - /emailbutler/ui, with opportunity to search, resend and/or destroy emails.
The gem is available as open source under the terms of the MIT License.