How to fix undefined method address_list in Rails 6.x and 7.x.

How to fix undefined method address_list in Rails 6.x and 7.x.

Updating the mail gem breaks Mail#address_list

ยท

1 min read

Table of contents

The problem

The other day I came across an issue where I saw this error:

# mail.address_list
NoMethodError: undefined method `address_list'

The error was coming from this line: https://github.com/rails/rails/blob/6-1-stable/actionmailbox/lib/action_mailbox/mail_ext/addresses.rb#L5-L7.

As I often like to do, I periodically review gem dependencies in an app and upgrade them to keep things, well... up-to-date.

In this situation, I updated the mail gem to version 2.8.x. It appears this was the root cause of the problem.

As it turns out, when the mail gem was released, it had broken Rails: https://github.com/rails/rails/pull/46643. The address_list was no longer part of the newly released mail gem.

The solution

It appeared that others were also having the same problem, and a solution was backported to Rails 6-1 and 7-0 stable:

As of this writing, these versions have not yet been released. So, a temporary fix may be to downgrade mail from 2.8.0 to 2.7.x.

Alternatively, one could use 6-1 or 7-0 stable and reference those versions in the Gemfile. It is expected that this fix should be available in Rails 6.1.8 and 7.0.5 when these will be released.

ย