3

I am following Ryan Bates's tutorial on Rails 3 ActionMailer. I generate the mailer in terminal and then establish a setup_mail.rb under config/initializers. I keyed in the following code:

ActionMailer::Base.smtp_settings={
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domail               => "gmail.com",
  :user_name            => "my_account_at_gmail",
  :password             => "my_password",
  :authentication       => "plain"  ,
  :enable_starttls_auto => true
}

My user_mailer.rb file goes like:

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

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

I tested in rails console: u=User.first UserMailer.registration_confirmation(u).deliver

it displays:

 #<Mail::Message:2194479560, Multipart: false, Headers: <Date: Sat, 26 Feb 2011 14:42:06 +0800>, <From: [email protected]>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: registered>, <Mime-Version: 1.0>, <Content-Type: text/plain>, <Content-Transfer-Encoding: 7bit>>

BUT I never received the email here... Why? How can I solve this? I guess it is some problem on send_mail.rb file..

2 Answers 2

2

If that's a copy/paste of your send_mail.rb, there is a spelling error in :domain (you have :domail) which may or may not be causing the issue.

If that doesn't work, try the following:

ActionMailer::Base.delivery_method = :smtp # be sure to choose SMTP delivery
ActionMailer::Base.smtp_settings = {
  :tls => true,
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "gmail.com",
  :authentication => :plain,
  :user_name => "[email protected]", # use full email address here
  :password => "password"
}
0
2

Alternatively, it has been been suggested in the Action Mailer Rails Edge Guide to put the email configuration in the appropriate .rb file in your config/environments directory. For me, I put the following in config/environments/development.rb to get emails sent using gmail's SMTP server:

config.action_mailer.raise_delivery_errors = true #useful to have to debug
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value

config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "yourdomain.com",
    :user_name => "[email protected]",
    :password => "yourpassword",
    :authentication => :login, #or can use "plain"
    :enable_starttls_auto => true
  }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.