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 => "my_account_at_gmai开发者_运维问答l@gmail.com"
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: my_account_at_gmail@gmail.com>, <To: some_account@gmail.com>, <Message-ID: <some_number@My-MacBook-Pro.local.mail>>, <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..
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 => "my_account_at_gmail@gmail.com", # use full email address here
:password => "password"
}
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 => "username@yourdomain.com",
:password => "yourpassword",
:authentication => :login, #or can use "plain"
:enable_starttls_auto => true
}
精彩评论