Skip to content

Allow providing computed method for To header #5762

Open
@DaAwesomeP

Description

Hello,

I am trying to do the following so that the mail header To field contains a user's name as well as email address.

class ApplicationDeviseMailer < Devise::Mailer
  default to: -> { computed_to }

  private

  def computed_to
    ApplicationMailer.email_address_with_name(resource.email, resource.name)
  end
end

However, there is not an option to transform the To field (only From and Reply-To):

def headers_for(action, opts)
headers = {
subject: subject_for(action),
to: resource.email,
from: mailer_sender(devise_mapping),
reply_to: mailer_sender(devise_mapping),
template_path: template_paths,
template_name: action
}
# Give priority to the mailer's default if they exists.
headers.delete(:from) if default_params[:from]
headers.delete(:reply_to) if default_params[:reply_to]
headers.merge!(opts)
@email = headers[:to]
headers
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions