Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow providing computed method for To header #5762

Open
DaAwesomeP opened this issue Feb 7, 2025 · 0 comments
Open

Allow providing computed method for To header #5762

DaAwesomeP opened this issue Feb 7, 2025 · 0 comments

Comments

@DaAwesomeP
Copy link

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

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

No branches or pull requests

1 participant