---
title: "Rails 5 allows configuring queue name for mailers"
description: "We can configure queue name for mailers with Rails 5"
canonical_url: "https://www.bigbinary.com/blog/rails-5-allows-configuring-queue-name-for-mailers"
markdown_url: "https://www.bigbinary.com/blog/rails-5-allows-configuring-queue-name-for-mailers.md"
---

# Rails 5 allows configuring queue name for mailers

We can configure queue name for mailers with Rails 5

- Author: Abhishek Jain
- Published: February 26, 2016
- Categories: Rails 5, Rails

In Rails 4.2, Active Job was integrated with Action Mailer to send emails
asynchronously.

Rails provides `deliver_later` method to enqueue mailer jobs.

```ruby

class UserMailer < ApplicationMailer
  def send_notification(user)
    @user = user
    mail(to: user.email)
  end
end

> UserMailer.send_notification(user).deliver_later
=> <ActionMailer::DeliveryJob:0x007ff602dd3128 @arguments=["UserMailer", "send_notification", "deliver_now", <User id: 1, name: "John", email: "john@bigbinary.com">], @job_id="d0171da0-86d3-49f4-ba03-37b37d4e8e2b", @queue_name="mailers", @priority=nil>

```

Note that the task of delivering email was put in queue called `mailers`.

In Rails 4.x, all background jobs are given queue named "default" except for
mailers. All outgoing mails are given the queue named "mailers" and we do not
have the option of changing this queue name from "mailers" to anything else.

Since Rails 4.x comes with minimum of two queues it makes difficult to use
queuing services like [que](https://github.com/chanks/que) which relies on
applications having only one queue.

## Customizing queue name in Rails 5

In Rails 5, we can now
[change queue name](https://github.com/rails/rails/pull/18587) for mailer jobs
using following configuration.

```ruby

config.action_mailer.deliver_later_queue_name = 'default'

class UserMailer < ApplicationMailer
  def send_notification(user)
    @user = user
    mail(to: user.email)
  end
end

2.2.2 :003 > user = User.last
=> <User id: 6, name: "John", email: "john@bigbinary.com">

2.2.2 :004 > UserMailer.send_notification(user).deliver_later
=> <ActionMailer::DeliveryJob:0x007fea2182b2d0 @arguments=["UserMailer", "send_notification", "deliver_now", <User id: 1, name: "John", email: "john@bigbinary.com">], @job_id="316b00b2-64c8-4a2d-8153-4ce7abafb28d", @queue_name="default", @priority=nil>
```

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-allows-configuring-queue-name-for-mailers)
