Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 actionmailer cannot send email

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..

like image 618
lkahtz Avatar asked Mar 05 '26 05:03

lkahtz


2 Answers

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"
}
like image 63
Michelle Tilley Avatar answered Mar 07 '26 21:03

Michelle Tilley


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
  }
like image 36
glacier Avatar answered Mar 07 '26 19:03

glacier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!