Mandrill for Rails Mailers on Heroku

mandrill.png
I have been busy for the last week trying to get my mailers to work correctly on Heroku. Even though you would think that this would be easy, for some reason I had the hardest time finding the correct information.

In order to get it right, I had to phone a friend….literally. I had intended for this to be a step by step guide for future reference, but instead I am just gonna drop the code(a.k.a. mic).

Boom!

config.action_mailer.default_url_options = { :host => 'address_for_host.herokuapp.com'
        Rails.application.routes.default_url_options[:host] = 'address_for_host.herokuapp.com'
          config.action_mailer.delivery_method = :smtp
          config.action_mailer.perform_deliveries = true
          config.action_mailer.raise_delivery_errors = false
          config.action_mailer.default :charset => "utf-8"
          config.action_mailer.smtp_settings = {
              :port => '587',
              :address => 'smtp.mandrillapp.com',
              :user_name => ENV['MANDRILL_USERNAME'],
              :password => ENV['MANDRILL_APIKEY'],
              :domain => 'heroku.com',
              :authentication => :plain
            }
        ActionMailer::Base.delivery_method = :smtp
        config.action_controller.include_all_helpers = true
        ActionMailer::Base.default :from => "MyApp<myapp@thisisyouremailaddress.com>"

ok…that was a bit dramatic. So I will break it down for you. This code above needs to be present in your production.rb file for rails app when you are using Mandrill.

What I didn’t know at first, that I know know is…… that in addition to adding the mandrill gem, you will also need to create the heroku add on. There is a good walkthru for adding the Heroku mandrill addon on Heroku’s site.

You should use it, and make sure that you have all the code in all the right places. And save yourself a few days of agony :)

 
26
Kudos
 
26
Kudos

Now read this

Microsoft vs Open Source Software

Lately there has been some talk about .Net framework becoming open source. .Net is Microsoft’s server-side client that is used in building web applications, among other things. Apparently, Microsoft’s choice to open source some of its... Continue →