I ended up in the following solution. This solution contains a case where you have several clients, and these clients may have their own email settings and their own domains / subdomains for URLs in emails.
I used my own mailer class and connected to the clientโs custom email settings:
configurations / Initializers / devise.rb:
config.mailer = "DeviseMailer"
config / secrets.yml:
development: mailer_settings: customers: customer_1_identifier_name: send: address: "smtp.gmail.com" port: 587 domain: "example" user_name: " test@example.com " email: " noreply@example.com " password: "secret" authentication: "plain"
Application / senders / devise_mailer.rb:
class DeviseMailer < Devise::Mailer layout 'mailer' after_action :set_email_settings_and_sender, only: [:reset_password_instructions, :confirmation_instructions] def reset_password_instructions(record, token, opts={}) @account = record.current_account if record.class == User # set the account of current_user - current_account is an own helper method super end def confirmation_instructions(record, token, opts={}) @account = record.current_account if record.class == User && record.unconfirmed_email.present? super end private # re-set the email settings for the given user and his account: def set_email_settings_and_sender if @account.present? && @account.custom_email_settings? mail.reply_to = nil settings = Rails.application.secrets.mailer_settings["customers"][@account.identifier_name]["send"].symbolize_keys mail.delivery_method.settings.merge!(settings) mail.from = "#{@account.display_name} <#{settings[:email]}>" end end end
Change the urls in the email view templates:
application / views / Testament / mailer / confirmation_instructions.html.erb
Just change the link to the new url options.
application / views / invent / reset_password_instructions.html.erb
<% if @account.present? && @account.domain.present? %> <% link = "#{@account.host_for_links}/auth/password/edit?reset_password_token=#{@token}" %> <a href="<%= link %>"><%= link %></a> <% else %> <a href="<%= edit_password_url(@resource, reset_password_token: @token) %>"><%= edit_password_url(@resource, reset_password_token: @token) %></a> <% end %>
That was my decision. If you have any questions, just let me know.
EDIT: Remember to specify the default url parameters in your environment. For example, in your development.rb file - config / environment / development.rb:
config.action_mailer.default_url_options = { host: "your-host.dev", port: 3000 }