Ruby on rails Rails 4:Net::调用ActionMailer时读取超时

Ruby on rails Rails 4:Net::调用ActionMailer时读取超时,ruby-on-rails,actionmailer,Ruby On Rails,Actionmailer,在开发模式下运行邮件程序时,出现以下错误: Net::ReadTimeout in SchoolApplicationsController#create 下面是获取超时的控制器方法 def create @school_application = SchoolApplication.new(school_application_params) @school_application.program_cost = @school_application.calcul

在开发模式下运行邮件程序时,出现以下错误:

Net::ReadTimeout in SchoolApplicationsController#create
下面是获取超时的控制器方法

  def create
    @school_application = SchoolApplication.new(school_application_params)
     @school_application.program_cost =    @school_application.calculate_cost_to_charge(params[:school_application][:program], params[:school_application][:duration])
    if @school_application.save

      NotificationsMailer.send_application(@school_application).deliver
      redirect_to application_path(@school_application.id)
    else  
      Rails.logger.debug(@school_application.errors.full_messages)
          @school_application.errors.full_messages.each do |msg|
        flash.now[:error] = msg
      end
      render action: "new"
    end
  end
我确信错误是由
NotificationsMailer
调用引起的,因为 我把它注释掉,我不再得到错误

这是我的邮件和设置:

class NotificationsMailer < ActionMailer::Base

  default :from => "from@slf.net"
  default :to => "nayr@slf.net"

  def send_application(application)
    @application = application 
    mail(:subject => "New Application")
  end
end
Fls::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
  address:              'secure3309.hostgator.com',
  port:                 465,
  domain:               'slf.net',
  ssl: true,
  user_name:            ENV['slf_username'],
  password:             ENV['slf_password'],
  authentication:       'plain',
  enable_starttls_auto: true  }
end
当我在Rails控制台中写入
ENV['slf_username']
时,我得到了正确的值。密码也一样。用户名的格式为user@slf.net. 这是正确的,还是正确的格式只是“用户”,并且域是从
参数中隐含的?

阅读本文后,我再次查看了我的smtp设置并添加了

tls: true 
改变
port:465
port:'465'
,因为我注意到大多数人都将其作为字符串编写。同样,将字符串
“plain”
更改为符号
:plain

在初始化中添加以下代码

require 'net/smtp'

module Net
  class SMTP
    def tls?
      true
    end
  end
end

当我将smtp邮件连接到qq邮件(商务邮件)时,我遇到了类似的问题。 我通过如下方式更新了我的设置:

config.action_mailer.smtp_settings = {
address:              'smtp.exmail.qq.com',
port:                 '465',
domain:               'groobusiness.com',
user_name:            ENV['GMAIL_USER_NAME'],
password:             ENV['GMAIL_PASSWORD'],
authentication:       :plain,
enable_starttls_auto: true,
openssl_verify_mode:  'none',
ssl:                   true,
tls:                   true
}
问题解决了。
希望它能对面临这个问题的人有所帮助。

看起来像
tls:true
是关键。我不相信其他的改变有什么关系。(还要注意的是
tls
,而不是
tsl
)这对我来说也很有效,但我希望我能回到生命的最后一个小时。