2017-03-06 22 views
0

我有一個應用程序部署在heroku中,郵件只發送成功,但不是在生產中發送。我正在使用mailgun。下面是錯誤的結果:Rails - 無法使用mailgun發送郵件到生產

Exception 
Net::OpenTimeout 
Error 
execution expired 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `initialize' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `open' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `tcp_socket' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:551:in `block in do_start' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:98:in `call' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:98:in `timeout' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:550:in `do_start' 
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:520:in `start' 
/app/vendor/bundle/ruby/2.2.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:113:in `deliver!' 
/app/vendor/bundle/ruby/2.2.0/gems/mail-2.6.4/lib/mail/message.rb:253:in `deliver!' 
/app/vendor/bundle/ruby/2.2.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb:77:in `deliver_now!' 
/app/vendor/bundle/ruby/2.2.0/gems/actionmailer-4.2.5/lib/action_mailer/delivery_job.rb:10:in `perform' 
/app/vendor/bundle/ruby/2.2.0/gems/activejob-4.2.5/lib/active_job/execution.rb:32:in `block in perform_now' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:498:in `block (2 levels) in around' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:343:in `call' 
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple' 
/app/vendor/bundle/ruby/2.2.0/gems/i18n-0.8.1/lib/i18n.rb:257:in `with_locale' 

和我的配置/環境/ production.rb代碼

config.action_mailer.delivery_method = :smtp 
    ActionMailer::Base.smtp_settings = 
    { 

    :address    => 'mailgun.org', 
    :port     => ENV['MAILGUN_SMTP_PORT'], 
    :domain    => ENV['MY_DOMAIN'], 
    :user_name   => ENV['MAILGUN_SMTP_LOGIN'], 
    :password    => ENV['MAILGUN_SMTP_PASSWORD'], 
    :authentication  => 'plain' 
    } 

    config.action_mailer.default_url_options = { :host => 'https://myapp.herokuapp.com/' } 
    config.action_mailer.asset_host = 'https://myapp.herokuapp.com/' 
    config.action_controller.asset_host = 'https://myapp.herokuapp.com/' 
+0

「production.rb」中的語法錯誤是不是給你帶來問題,還是隻是一個錯字? – Iceman

+0

你對MAILGUN_SMTP_PORT有什麼用?如果它是25,那麼這可能是問題 - 嘗試切換到587每個討論在這裏:http://blog.mailgun.com/25-465-587-what-port-should-i-使用/ – Brian

+0

@布賴恩我已經嘗試過,但仍然沒有運氣。 – romiesilvano

回答

0

好吧,我沒注意,我只用「mailgun.org」而不是' smtp.mailgun.org「爲地址。我將地址值更改爲ENV ['MAILGUN_SMTP_SERVER'],然後它在生產中正常工作。