Rails Action Mailer not sending email

I ran into this same problem for a new mailer I had setup. I couldn't figure out for the life of me why this new mailer couldn't send emails, or even get to the method in the mailer when I stepped through it.

Solution

It ended up being that if you put the deliver_now or deliver* code within the mailer, it does not send the email.

Example Broken

  def email_message()
    message = mail(to: User.first, subject: 'test', body: "body text for mail")
    message.deliver_now
  end

Corrected

  #Different class; in my case a service
  def caller
    message = MyMailer.email_message
    message.deliver_now
  end

  def email_message()
    mail(to: User.first, subject: 'test', body: "body text for mail")
  end

This solved the problem for me, I hope it solves it for someone else.


Make sure you have this option set in your config/environments/development.rb :

config.action_mailer.delivery_method = :smtp

Also, in ActionMailer::Base.smtp_settings you need to specify a valid gmail account. Copy-pasting (asciicasts) is not gonna cut it here.

See this question for reference: Sending mail with Rails 3 in development environment


Instead of 'smtp' you can use 'sendmail'

ActionMailer::Base.delivery_method = :sendmail

ActionMailer::Base.sendmail_settings = { :address => "smtp.gmail.com",
     :port => "587", :domain => "gmail.com", :user_name => "[email protected]", 
    :password => "yyy", :authentication => "plain", :enable_starttls_auto => true }