A mailbox that does not send emails after upgrading to Rails 5.0.6

I upgraded the Rails application to 5.0.6 from 4.2.5. Now emails are not sent using the Mail gem. I don't seem to get any errors. I updated the zip stone to the latest version with no luck. I'm not sure what else to try.

I run:

Rails 5.0.6

Ruby 2.3.0

Mail 2.7.0

Controllers / send_email.rb

class SendEmail < ApplicationController def initialize(to_address, from_address, email_pass, subject, body) begin options = { :address => 'abc.prod.1234.secureserver.net', :port => '465', :domain => 'mydomain.com', :user_name => from_address, :password => email_pass, :authentication => :login, :ssl => true, :openssl_verify_mode => 'none' } Mail.defaults do delivery_method :smtp, options end Mail.deliver do to to_address from from_address subject subject body body end puts("\nSent message. From: #{from_address} To: #{to_address} \nMessage body: \n#{body}") return true rescue Exception => e puts e.to_s return false end end end 

Update:

I tried sending an email using Action Mailer. He says that he goes to the console, but he never gets delivered. I use the same settings for Action Mailer, since I use a mail stone.

configurations / environment / development.rb

  config.action_mailer.smtp_settings = { :address => 'abc.prod.1234.secureserver.net', :port => '465', :domain => 'mydomain.com', :user_name => ENV['default_username'], :password => ENV['default_password'], :authentication => :login, :ssl => true, :openssl_verify_mode => 'none' } 

I run this from the console:

 EmailMailer.sample_email(UserEmail.first) 

Console output:

  Rendering email_mailer/sample_email.html.erb within layouts/mailer Rendered email_mailer/sample_email.html.erb within layouts/mailer (0.1ms) Rendering email_mailer/sample_email.text.erb within layouts/mailer Rendered email_mailer/sample_email.text.erb within layouts/mailer (0.0ms) EmailMailer#sample_email: processed outbound mail in 9.4ms 

Decision:

I have a code that sends an email when there is an unknown error that I need to look at. When I update Rails, this code got into a loop that quickly sent a bunch of emails. This made my server provider mark my email account as a spam account. I don’t know why there were no errors in my source code, but when I started EmailMailer.sample_email(UserEmail.first).deliver_now , it gave me an error message that helped me track it.

+5
source share
1 answer

Well, wild assumptions are here, but try this:

 EmailMailer.sample_email(UserEmail.first).deliver_now 

If you had a version of Rails below 4.2.1, there was no need to call to deliver to the mail object for delivery. From now on, you can work with the mail object before it is delivered, which can now be used by .deliver_now or later using .deliver_later , which is accompanied by the use of ActiveJob or another queue library.

+3
source

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


All Articles