Getting started with Midflight in Rails

Welcome to Midflight's Ruby on Rails integration guide. By following the steps below, you'll be ready to send your emails with Midflight in no time. This guide assumes that you are familiar with Rails and its ActionMailer.

1. Before we start

Make sure you have your unique BCC address provided by Midflight. You can find it in the onboarding page of your project or in the settings page.

2. Update your ApplicationMailer

Integrating Midflight with your Rails app is straightforward. Here's an example snippet to add to your ApplicationMailer class:

class ApplicationMailer < ActionMailer::Base
  after_action :midflight_setup


  def midflight_setup
    mail.bcc ||= []
    mail.bcc << ""

    headers["X-Midflight-Template"] = "#{mailer_name}##{action_name}"
    headers["X-Midflight-Locale"] = locale

Detailed explanation:

mail.bcc << "": This line adds your unique Midflight BCC address to every outgoing email. Don't forget to replace the address with the one provided by Midflight.

headers["X-Midflight-Template"]: Set this to a unique identifier for each mail template, constructed from the mailer's class name and the specific action.

headers["X-Midflight-Locale"]: This should be set to the current locale of the email, allowing for proper localization tracking within Midflight.

3. Test your integration

After setting up the code, send a test email to verify that Midflight is capturing it. You should see the email appear on your Midflight dashboard.


If your emails aren't appearing in Midflight:

  • Double-check your BCC address.
  • Make sure you're setting the headers correctly in every email.
  • Review your environment settings to ensure emails are being sent.

For further assistance, reach out to us at

© 2024 Midflight. All rights reserved