2014-10-02 13 views
9

Khi tôi chạy bưu phẩm của tôi trong chế độ phát triển, tôi nhận được lỗi sau:Rails 4: Net :: ReadTimeout khi gọi ActionMailer

Net::ReadTimeout in SchoolApplicationsController#create 

Dưới đây là phương pháp điều khiển mà là nhận được thời gian chờ

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 

Tôi rất tích cực khi xảy ra lỗi do cuộc gọi NotificationsMailer vì khi Tôi nhận xét, tôi không còn gặp lỗi nữa.

Đây là bưu phẩm của tôi, và các cài đặt:

class NotificationsMailer < ActionMailer::Base 

    default :from => "[email protected]" 
    default :to => "[email protected]" 

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

Dưới đây là các thiết lập environments/development.rb smtp của tôi:

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 

Khi tôi viết ENV['fls_username'] trong Rails console Tôi nhận được giá trị đúng. Cùng với mật khẩu. Tên người dùng có định dạng [email protected] Có đúng hay đúng định dạng "người dùng" và tên miền được ngụ ý từ thông số domain?

Trả lời

27

Sau khi đọc này post tôi đã nhìn khác ở các cài đặt smtp của tôi và thêm

tls: true 

thay đổi port: 465 để port: '465' như tôi nhận thấy rằng hầu hết mọi người viết nó như là một chuỗi. Cũng Tương tự thay đổi chuỗi "plain" vào biểu tượng :plain

+6

Có vẻ như 'tls: true' là khóa. Tôi không tin những thay đổi khác quan trọng. (Cũng lưu ý nó là 'tls', không phải' tsl'.) –

+0

Tôi xác nhận, vì tôi đã thêm 'tls: true'. – mwangi

+1

điều này cũng có tác dụng đối với tôi, nhưng tôi ước tôi có một giờ cuối cùng trong đời. –

-1

add sau mã trong intitialize

require 'net/smtp' 

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

tôi phải đối mặt với vấn đề tương tự khi tôi kết nối qua đường bưu điện smtp để qq mail (email kinh doanh). tôi cập nhật cài đặt của tôi bằng cách làm theo các post như như dưới đây:

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 
} 

Và vấn đề này đã được giải quyết. Hy vọng điều đó có thể hữu ích đối với người đang đối mặt với vấn đề này.

Các vấn đề liên quan