Rails 3 actionmailer cannot send email

I am following the Ryan Bates tutorial on Rails 3 ActionMailer . I create a mailbox in the terminal and then set setup_mail.rb in config / initializers. I entered 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
}

The user_mailer.rb file is as follows:

class UserMailer < ActionMailer::Base
  default :from => "my_account_at_gmail@gmail.com"

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

I tested in the rails console: and = User.first UserMailer.registration_confirmation (s) 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 got an email here ... Why? How can i solve this? I think this is a problem in the send_mail.rb file.

+3
source share
2 answers

/ send_mail.rb, :domain ( :domail), .

, :

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"
}
+2

, Action Mailer Rails Edge Guide .rb config/environment. config/environment/development.rb , SMTP gmail:

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
  }
+2

Source: https://habr.com/ru/post/1794881/


All Articles