2014-10-02 63 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 
} 

而且問題得到有效解決。 希望對面臨此問題的人有所幫助。