How do I send two different confirmation letters that can be confirmed and redeveloped?

Both devices prepare confirmation (confirmation by e-mail when registering the user) and re-confirm (confirmation by e-mail when changing the name of the e-mail), the modules send the same e-mail template "confirm_instructions". How can I get it so that a different email template is used for confirmation?

+4
source share
3 answers

You can override options[:template_name] in the #confirmation_instructions method of your mailer.

 class AuthMailer < Devise::Mailer helper :application include Devise::Controllers::UrlHelpers default template_path: 'devise/mailer' def confirmation_instructions(record, token, options={}) # Use different e-mail templates for signup e-mail confirmation and for when a user changes e-mail address. if record.pending_reconfirmation? options[:template_name] = 'reconfirmation_instructions' else options[:template_name] = 'confirmation_instructions' end super end end 

Also change this line to device.rb

 # config.mailer = 'Devise::Mailer' config.mailer = 'AuthMailer' 
+6
source
 #Devise Mailer def confirmation_instructions(record) @resource = record if @resource.pending_reconfirmation? mail(to: @resource.unconfirmed_email, subject: "Confirm new email") do |format| format.html { render ... } end else mail(to: @resource.email, subject: "Confirm new account") do |format| format.html { render .... } end end end 
+5
source

I just looked at the documents and there was a send_on_create_notification method, which can be overridden in the model. Therefore, you just need to override this method so that the confirmation email is not sent, but another one is sent instead. In this letter I will only have a confirmation link.

0
source

All Articles