Site icon Mailtrap

ActionMailer Balancer: Keeping the Email Sending Equilibrium

Can your sending reputation and domain authority switch Email Service Providers (ESPs) together with you? Will the migration from the SMTP to the API affect your email deliverability? How to keep up with your usual sending volumes without a drop? How to mitigate sending risks and be able to deliver those VERY IMPORTANT emails to your customers’ inboxes no matter what?

Now, Mailtrap has developed the answer to all these questions for Ruby applications: the ActionMailer Balancer. 


What is the ActionMailer Balancer?

Mailtrap ActionMailer Balancer is an ActionMailer extension that works, well, surprise, as a balancer! It allows proportionally distributing the email sending load between two different sending services and keeping the sending equilibrium in the percentage you need and set up for yourself. For example: 

SendGrid 70% / Mailtrap 30%. 

or 

Postmark 60% / Mailgun 40%.

The Balancer works with any valid ActionMailer delivery method, either built-in, or added from the library, like the one from Mailtrap.

How ActionMailer Balancer works

After you install the Balancer to your application, and do some minor configurations, it will extend the sending method of ActionMailer. 

The uniqueness of the gem is that for both sending services (whichever you choose), ActionMailer Balancer decides what sending solution to use even before ActionMailer is called. 

Let’s say you use SendGrid as your major email sending solution, and then you decide to migrate to Mailtrap for any reason possible (legal, financial, server location etc). You can’t (actually you can, but better not do that by all means)  migrate just in one step since your emails sent with the new ESP, Mailtrap in this particular case, would be recognized as spam.  Thus, you need to move slowly, step by step, increasing the volume of emails you send from Mailtrap. This is where the ActionMailer Balancer gem comes into play.

Why you may need the ActionMailer Balancer

There are a few use cases that you may consider. All of them are about mitigating email sending risks.

The smooth migration from one Email Service Provider (ESP) to another. It is hard to switch immediately, especially if you are a big sender. The gradual warm-up of the IP, building up senders’ reputation, stability, and reliability of the sending infrastructure all come to play. You need a recommended schedule for migration starting from 1%. We, at Mailtrap, can offer our recommendations in this regard, while Mailtrap ActionMailer Balancer gem will do the technical part.

Spread the sending load between two ESPs. This has been widely discussed above. In this case, the Balancer runs the email side of your business with two different sending solutions which you might need for whichever reason. It is not about sending limits though since the Balancer sends emails based on proportion, not on the limits or availability of any of the methods.

Spread the sending load between two ESPs. This has been widely discussed above. In this case, the Balancer runs the email side of your business with a sending backup already set and working.

Switch from SMTP to API app configurations for sending. This case would also call for the gradual migration process according to certain rules not to ruin your email deliverability. The Balancer gem helps to keep the sending equilibrium in place.

What is the main benefit of the ActionMailer Balancer?

Consistency and reliability in email sending. The Mailtrap Balancer helps you to not lose your overall deliverability nor your senders’ reputation since your second sending service’s IP has already been warmed up by the n% of sending traffic you dedicated to it initially.

At the moment, you can connect any sending services you need. SendGrid with Mailtrap, Postmark with Mailgun etc. 

Other benefits include: 

Is the Mailtrap ActionMailer Balancer secure?

Yes, it is. 

The Balancer works within your application and doesn’t require any additional services, plug-ins, or whatever. Basically, the sending process per se doesn’t change after installing the ActionMailer Balancer. The app keeps sending the way it used to send, only now it uses one of several delivery methods, selected by percentage.

How to start using the ActionMailer Balancer: step-by-step guide

Install the Balancer. You can do it in two ways:

  1. If you use bundler,  add this line to your application’s Gemfile gem 'actionmailer-balancer' and then execute $ bundle install
  2. Otherwise, install through: $ gem install actionmailer-balancer

 Add the necessary configurations to hold the settings:

Your::Application.configure do
  config.action_mailer.delivery_method = :balancer
  config.action_mailer.balancer_settings = {
    delivery_methods: [
      {
        method: :smtp,
        settings: {
          user_name: username,
          password: password,
          address: host,
          domain: domain,
          port: port,
          authentication: auth_method
        },
        weight: 90
      },
      {
        method: :sendmail,
        settings: {
          location: '/path/to/your/sendmail'
        },
        weight: 10
      }
    ]
  }
end

Now, just use ActionMailer as usual, and your email loads for sending will be auto-balanced and sent.

For more detailed info on the boilerplate and use in development, check out the Mailtrap ActionMailer Balancer Github page.

Note: Considering DNS records. Mailtrap prepares SPF records automatically, contrary to other ESPs. 

To connect, let’s say, SendGrid with Mailtrap, you need to have SendGrid’s SPF DNS records and the ones of Mailtrap. The SPF line will be completely parsed, so the SPF line in the DNS records is already prepared in the Balancer when you install and run it. All you need to do is just copy and paste it.

Instead of a conclusion

Mailtrap ActionMailer Balancer was created for projects, developers, and businesses working with Ruby on Rails frameworks. 

The Balancer ensures that whatever efforts you take in email sending, they will be balanced-out, your deliverability will be consistent, and your thoughtfully crafted emails will be delivered to recipients no matter what.

Exit mobile version