Tracking status of sending emails from your Ruby on Rails application

Anton Bogdanov
2 min readSep 16, 2022

--

In general all Ruby on Rails applications have email delivering layer with using some SMTP provider like Sendgrid, Mailgun, Mailchimp or any other. And for checking delivery status of your emails you need visit dashboard of SMTP provider, where you can see info about sender and receiver of all messages.

But lets imaging that you missed email from Sendgrid about payment time and all your emails stucked in processed status for a week, and now you can’t exactly know what mailers you need to call to resend all this stucked messages (because Sendgrid will not re-send them).

In such case what can help you is small Rails engine. It works very simple, at the moment of creating some email by mailer, Emaibutler creates object in database with different statistic. Then when SMTP provider sends report about statuses of your emails to special webhooks controller (from engine), Emailbutler updates status of sent emails.

What is required for engine working:

  • add gem to Gemfile,
  • include helper to application mailer,
  • update routes,
  • and update SMTP provider settings to send requests to your application.

After that you can create job for checking delivery status of email. For example:

Emailbutler::Message.where(status: ['created', 'rejected', 'failed'])

This code will return list of messages that were not even delivered to SMTP provider or provider returned failed delivery status for those emails.

And now for each email, unlike the provider, you will have data about mailer that generated this email — mailer name, mailer action, provided params for email generation, so you can easily re-generate the failed emails.

Engine is in active development, right now it works only with Sendgrid (but other providers will be added soon) and ActiveRecord as ORM.

--

--