Confirmation email from devise on rails3 using gmail not arriving

谁说胖子不能爱 提交于 2019-12-04 20:52:47

问题


I've set the following up.

----------------------
config/environments/development.rb
----------------------
 29   ActionMailer::Base.delivery_method = :smtp
 30   ActionMailer::Base.perform_deliveries = true
 31   ActionMailer::Base.raise_delivery_errors = true
 32  
 33   ActionMailer::Base.smtp_settings = {
 34     :enable_starttls_auto => true,  #this is the important stuff!
 35     :address        => 'smtp.gmail.com',
 36     :port           => 587,
 37     :domain         => 'foo.com',
 38     :authentication => :plain,
 39     :user_name      => '---@---.---',
 40     :password       => '---'
 41   }

However when devise sends the confirmation email webbrick prints out the email in the log with no error but the email does not end up in my inbox or spam inbox.

Any ideas?

EDIT:

I now get

    Net::SMTPAuthenticationError (530 5.7.0 Must issue a STARTTLS command first. x13sm2646038bki.0

):

I found that

----------------------
config/environments/development.rb
----------------------
 17   # Don't care if the mailer can't send
 18   config.action_mailer.raise_delivery_errors = false

Had been set higher up in the config file. However what is this about issuing a STARTTLS command?

SOLUTION:

----------------------
config/environments/development.rb
----------------------
 26   require 'tlsmail' #key but not always described
 27   Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
 28  
 29   ActionMailer::Base.delivery_method = :smtp
 30   ActionMailer::Base.perform_deliveries = true
 31   ActionMailer::Base.raise_delivery_errors = true
 32  
 33   ActionMailer::Base.smtp_settings = {
 34     :enable_starttls_auto => true,  #this is the important stuff!
 35     :address        => 'smtp.gmail.com',
 36     :port           => 587,
 37     :domain         => 'xtargets.com',
 38     :authentication => :plain,
 39     :user_name      => '-------',
 40     :password       => '-------'
 41   }
 42  

Brad


回答1:


I had the very same problem; in my case was due to a bug (Net::SMTP does not how to speak TLS, which is required by gmail) and I solved it as explained here.




回答2:


Rather than turning off SSL cert verification globally, you can pass an extra parameter to smtp_settings:

config.action_mailer.smtp_settings = {
  :address              => 'smtp.example.com',
  :port                 => '25',
  :domain               => 'example.com',
  :user_name            => 'someone@example.com',
  :password             => 'secret',
  :authentication       => 'plain',
  :enable_starttls_auto => true,
  :openssl_verify_mode  => OpenSSL::SSL::VERIFY_NONE,
}

You may also need to require 'openssl' to get that constant.

This solution also works with Pony, if you include :openssl_verify_mode in the :via_options hash.



来源:https://stackoverflow.com/questions/3794669/confirmation-email-from-devise-on-rails3-using-gmail-not-arriving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!