Search code examples
ruby-on-railsrubyherokuactionmailergemfile

Action Mailer - Heroku Push


I am new to action_mailer and I have no clue what could be going wrong. I've spent the last 12 hours going in circles with this. It might be a gem dependency, it might be something I did wrong. Please help!

Mailing works in my local environment, but I can't push to heroku. I keep getting this error:

-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   NoMethodError: undefined method `action_mailer' for #<Rails::Application:
:Configuration:0x00000002fad208>

EDIT NEW ERROR AFTER ADDING RAILS VERSION TO GEM FILE

Running: rake assets:precompile
       I, [2014-04-01T14:00:22.863048 #796]  INFO -- : Writing /tmp/build_a1da56
       f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/blank_tan_vig-03e2648e62e03d21bb6cb
       8e57937edf8.jpg
       I, [2014-04-01T14:00:22.865246 #796]  INFO -- : Writing /tmp/build_a1da56
       f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/rails-5c3c576fb6f357c0c4d2a32214da4
       4b6.png
       I, [2014-04-01T14:00:27.585107 #796]  INFO -- : Writing /tmp/build_a1da56
       f1-c7f3-455c-9bea-c9bf4306ef11/public/assets/application-bc6a900b1f1dc90eba371ab
       1e65adb36.js
       rake aborted!
       NoMethodError: undefined method `environment' for nil:NilClass

I am trying to use Mandrill for my SMTP server. I have the heroku addon installed and configured properly (as far as I could tell). I followed this: https://devcenter.heroku.com/articles/mandrill

user_mailer:

class UserMailer < ActionMailer::Base
  default from: "[email protected]"

  def send_welcome_email(user)
      @user = user
  mail(to: @user.email, subject: "Welcome to Myflix!")
  end
end

Production Env

Myflix::Application.configure do

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
   :address              => 'smtp.mandrillapp.com',
   :port                 => 587,
   :user_name            => ENV['MANDRILL_USERNAME'],
   :password             => ENV['MANDRILL_APIKEY'], # SMTP password is any valid API key
   :domain               => 'heroku.com', # your domain to identify your server when  connecting
   :authentication       => 'plain' # Mandrill supports 'plain' or 'login'
 }

 config.cache_classes = true
 config.eager_load = true
 config.consider_all_requests_local       = false
 config.action_controller.perform_caching = true

 config.serve_static_assets = false

 config.assets.compress = true
 config.assets.js_compressor = :uglifier

 config.assets.compile = false

 config.assets.digest = true

 config.i18n.fallbacks = true

 config.active_support.deprecation = :notify
end

Gemfile:

source 'https://rubygems.org' ruby '1.9.3'

gem 'bootstrap-sass'
gem 'coffee-rails'
gem 'rails', '4.0.0'
gem 'haml-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'jquery-rails'
gem 'bootstrap_form'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'fabrication'
gem 'faker'


group :development do
  gem 'sqlite3'
  gem 'pry'
  gem 'pry-nav'
  gem 'thin'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'letter_opener'
end

group :development, :test do
    gem 'rspec-rails'
end

group :test do
    gem 'shoulda-matchers'
  gem 'capybara'
  gem 'launchy'
end

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

Solution

  • Specify what version of Rails do you use in your Gemfile

    For example, if you use Rails 3.2.13:

    gem 'rails', '3.2.13'

    or if you use Rails 4

    gem 'rails', '4.0.0' `

    Run bundle install

    Hope that works.