Note that there are some explanatory texts on larger screens.

plurals
  1. POrails 3 + devise: how to modify the mailer method for confirmation emails to add user's second email address
    text
    copied!<p><strong>Background:</strong> In our app, we often have a sales rep do the setup for our customer using the salesperson's computer (often customers don't have access to their email at the time we set them up). So we're thinking to add a field to the devise registration form for the sales rep's email address and have the confirm link ALSO go to that email address.</p> <p><strong>Question:</strong> Is there a way to tell devise to bcc (or cc) the initial confirmation email (<strong>only the initial confirmation email</strong>) to an (optional) "backup_email" email address that is also provided on the new user registration form?</p> <p>Alternatively, is there a way to 'disable' the confirmation email process but ONLY when a certain code is entered into the registration field?</p> <p>I know how to add another field to the devise registration form, but I don't see how/where to modify the devise mailer code so when a confirmation email is sent to the "email" address it ALSO goes to the "backup_email" address (if any, sometimes it's blank).</p> <hr> <p>Thanks to Johnny Grass!</p> <p>I did <code>rails generate mailer CustomerUserMailer</code> and added</p> <pre><code>#config/initializers/devise.rb config.mailer = "CustomUserMailer" </code></pre> <p>my custom mailer looks like:</p> <pre><code># app/mailers/customer_user_mailer.rb class CustomUserMailer &lt; Devise::Mailer def headers_for(action) headers = { :subject =&gt; translate(devise_mapping, action), :from =&gt; mailer_sender(devise_mapping), :to =&gt; resource.email, :cc =&gt; resource.backup_user_email(action), :template_path =&gt; template_paths } end end </code></pre> <p>Then I moved the 3 mailer templates FROM <code>views/devise/mailer</code> to <code>views/customer_user_mailer</code> (otherwise the emails are empty)</p> <p>Then I added a method to my <code>User</code> model called <code>backup_user_email()</code> that returns the 'backup' email address (if any) based on the data in the user record and the action. The only "trick" there is that when testing the <code>action</code> it is not <code>action == "confirmation_instructions"</code> it is <code>action == :confirmation_instructions</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload