send email ruby on rails

1

I want you to check if it is true and send the mail, but the mail does not arrive.

reunion.rb

after_save :autorizar

def  autorizar
  if self.auto = true 
    ReunionMailer.autorizar_email(Reunion.find(self.id)).deliver 
  end
end

setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "gmail.com",        #este es el dominio
  :user_name            => "[email protected]",
  :password             => "lucas",
  :authentication       => "plain",
  :enable_starttls_auto => true
}

reunion_mailer.rb

class ReunionMailer < ApplicationMailer
  default from: '[email protected]'

  def autorizar_email(reunion)
    @reunion = reunion
    @url  = 'http://example.com/login'
    mail(to: @reunion.email, subject: 'AUTORIZACION')
  end
end

application_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: '[email protected]'
  layout 'mailer'
end

authorize_email.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Bienvenido</h1>
    <p>
      Esto es un ejemplo de envío de correos en una aplicación de Ruby on Rails<br>
      ya  esta autorizando
    </p>

    <p>Thanks for joining and have a great day!</p>
  </body>
</html>

Gemfile

gem 'mail'

    
asked by MIGUEL ANGEL GIL RODRIGUEZ 18.10.2017 в 16:18
source

1 answer

0

The deliver method has been depreciated in Rails 5 and replaced by the methods deliver_now (to send immediately) and deliver_later (to send later); therefore try to replace the use of deliver with any of these alternatives; for example:

def  autorizar
  if self.auto = true 
    ReunionMailer.autorizar_email(Reunion.find(self.id)).deliver_now
  end
end

Additionally, Rails gives you the option of not generating exceptions when an error is generated when sending an email; this is useful to prevent the application in productive from showing an error screen to the user (finally, the mailing usually does not part of the application flow).

However, it is important to enable this development option , allowing exceptions to be generated when a mailing fails, and thus be able to debug the code more easily; to enable this option you must add (in case it is not) the following line in the file config / environments / development.rb :

config.action_mailer.raise_delivery_errors = true

Remember that whenever this file is modified you must restart the Rails server for the changes to take effect.

    
answered by 18.10.2017 / 17:11
source