2014-10-02 56 views
9

当我在开发模式下运行我的邮件时,我收到以下错误:轨道4:网:: ReadTimeout调用的ActionMailer

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 
     Rails.logger.debug("Hey mufugga") 
     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 => "[email protected]" 
    default :to => "[email protected]" 

    def send_application(application) 
    @application = application 
    mail(:subject => "New Application") 
    end 
end 

这里是我的environments/development.rb SMTP设置:

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:    'secure3209.hostgator.com', 
    port:     465, 
    domain:    'fls.net', 
    ssl: true, 
    user_name:   ENV['fls_username'], 
    password:    ENV['fls_password'], 
    authentication:  'plain', 
    enable_starttls_auto: true } 
end 

当我在Rails的控制台写ENV['fls_username']我得到正确的值。与密码相同。用户名格式为[email protected]。这是正确的还是正确的格式只是“用户”,并且该域暗含domain参数?

回答

27

阅读本post之后我又看看我的SMTP设置并添加

tls: true 

改变 port: 465port: '465',因为我注意到,大多数人把它写成一个字符串。也同样改变了串"plain"到符号:plain

+6

看起来'tls:true'是关键。我不相信其他变化很重要。 (还要注意它是'tls',而不是'tsl'。) – 2014-11-15 06:16:37

+0

我确认,为我添加'tls:true'工作。 – mwangi 2016-08-18 13:46:06

+1

这也适用于我,但我希望我有我生命中的最后一个小时。 – 2017-10-04 01:26:54

-1

附加继intitialize

require 'net/smtp' 

module Net 
    class SMTP 
    def tls? 
     true 
    end 
    end 
end 
1

我面对类似的问题,当我连接SMTP邮件到QQ邮箱(企业邮箱)代码。 我通过遵循post像下面更新我的设置:

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 
} 

而且问题得到有效解决。 希望对面临此问题的人有所帮助。