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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With