I’ve had the “joy” of working with Salesforce.com in the last year or so. When users receive emails from my application, the sales department wants to know about it, including anything that Devise sends (account confirmations, password resets, etc.).

Setting this up is fairly simple. I’m using Devise 3.1.1 in this instance.

First, create a custom mailer:

rails generate mailer CustomDeviseMailer

Then, to config/initializers/devise.rb, add this line:

config.mailer = "CustomUserMailer"

Finally, change app/mailers/custom_devise_mailer.rb to look like this:

class CustomDeviseMailer < Devise::Mailer
  def headers_for(action, opts)
    if Rails.env.production?
      salesforce_bcc_email = "(your Email to Salesforce address)"
    else
      salesforce_bcc_email = "salesforce_bcc_email@mailinator.com"
    end

    super.merge!({bcc: salesforce_bcc_email})
  end
end

If you need to know where your Salesforce BCC email is:

  1. login to Salesforce
  2. In the top bar click your name, choose “Setup” from the menu
  3. Under “Personal Setup” in the left sidebar, click “Email”
  4. Under the email menu you just expanded, click “My Email to Salesforce”
  5. On that page it’s highlighted with a bright yellow box

Kudos to this StackOverflow question for getting me all fixed up in Devise 3.

Advertisement