Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Action Mailer not sending email

I am a complete beginner in Rails and I'm trying to send an email after someone signs up using Action Mailer.

My logs say that the email is sending, but Gmail never gets it.

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "asciicasts.com",
  :user_name            => "asciicasts",
  :password             => "secret",
  :authentication       => "plain",
  :enable_starttls_auto => true
}

mailers/user_mailer.rb

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

  def registration_confirmation(user)
    mail(:to => user.email, :subject => "Registered")
  end
end

controllers/users_controller.rb

...
def create
    @user = User.new(params[:user])
    if @user.save
      UserMailer.registration_confirmation(@user).deliver
      sign_in @user
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end
...

Thanks!

like image 720
Pavel Babin Avatar asked May 25 '13 21:05

Pavel Babin


1 Answers

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

like image 192
mihai Avatar answered Nov 15 '22 22:11

mihai