Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Overriding Devise Mailer

I am working on an app that is tightly being integrated in with Mandrill (MailChimp's transactional email service) and I am trying to override the Devise Mailer but for some reason when I send off the API call to Mandrill I receive their email, but Devise also sends me an email (which is blank).

Here is my DeviseMailer

class MyDeviseMailer < Devise::Mailer
  def reset_password_instructions(record)
    mandrill = Mandrill::API.new("#{MandrillConfig.api_key}")
    mandrill.messages 'send-template',
            { 
              :template_name => 'Forgot Password', 
              :template_content => "",
              :message => {
                :subject => "Forgot Password",
                :from_email => "[email protected]",
                :from_name => "Company Support",
                :to => [
                  {
                    :email => record.email
                  }
                ],
                :global_merge_vars => [
                  {
                    :name => "FIRST_NAME",
                    :content => record.first_name
                  },
                  {
                    :name => "FORGOT_PASSWORD_URL",
                    :content => "<a href='#{edit_user_password_url(:reset_password_token => record.reset_password_token)}'>Change My Password</a>"
                  }
                ]
              }
            }
      #We need to call super because Devise doesn't think we have sent any mail 
      super
  end
end

The call to super I found here: http://qnundrum.com/answer.php?q=254917

like image 300
dennismonsewicz Avatar asked Dec 04 '12 17:12

dennismonsewicz


People also ask

What is action_ Mailer in Rails?

Action Mailer allows you to send emails from your application using a mailer model and views. So, in Rails, emails are used by creating mailers that inherit from ActionMailer::Base and live in app/mailers. Those mailers have associated views that appear alongside controller views in app/views.


1 Answers

I was running into a similar issue.

Did you update the devise initializer file (devise.rb) to specify the following:

config.mailer = "MyDeviseMailer"  

You also needed to move any and all files in views/devise/mailer to views/mydevisemailer.

I would also restart your server.

like image 137
bigtex777 Avatar answered Oct 22 '22 05:10

bigtex777