【发布时间】:2015-06-15 13:59:47
【问题描述】:
我已经使用 Capistrano 将 Rails 4 应用程序部署到运行 Debian 7 的 Google Compute Engine 实例。我使用 Nginx 作为网络服务器,Passenger 作为应用程序服务器。对于发送电子邮件,我使用的是 Sendgrid,我的 staging.rb 文件中有以下内容
config.action_mailer.default_url_options = { host: 'smtp.sendgrid.net', port: 2525 }
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:user_name => '<my_sendgrid_username>',
:password => '<my_sengrid_password>',
:domain => '<ip address of my instance>',
:address => 'smtp.sendgrid.net',
:port => '2525',
:authentication => 'plain',
:enable_starttls_auto => true
}
我还使用谷歌云控制台在我的实例的防火墙上打开了端口 2525。但是,当我的 rails 应用程序尝试发送电子邮件时,我得到 Net::OpenTimeout 异常。下面是异常跟踪的一部分
Net::OpenTimeout (execution expired):
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:541:in `initialize'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:541:in `open'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:541:in `tcp_socket'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:551:in `block in do_start'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:89:in `block in timeout'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:99:in `call'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/timeout.rb:99:in `timeout'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:550:in `do_start'
/home/jimcgh/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/smtp.rb:520:in `start'
mail (2.6.3) lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
mail (2.6.3) lib/mail/message.rb:2141:in `do_delivery'
mail (2.6.3) lib/mail/message.rb:236:in `block in deliver'
actionmailer (4.2.1) lib/action_mailer/base.rb:543:in `block in deliver_mail'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionmailer (4.2.1) lib/action_mailer/base.rb:541:in `deliver_mail'
mail (2.6.3) lib/mail/message.rb:236:in `deliver'
actionmailer (4.2.1) lib/action_mailer/message_delivery.rb:85:in `deliver_now'
devise (3.5.1) lib/devise/models/authenticatable.rb:170:in `send_devise_notification'
devise (3.5.1) lib/devise/models/confirmable.rb:114:in `send_confirmation_instructions'
devise (3.5.1) lib/devise/models/confirmable.rb:170:in `send_on_create_confirmation_instructions'
activesupport (4.2.1) lib/active_support/callbacks.rb:432:in `block in make_lambda'
activesupport (4.2.1) lib/active_support/callbacks.rb:228:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:228:in `block in halting_and_conditional'
activesupport (4.2.1) lib/active_support/callbacks.rb:506:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:506:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:506:in `each'
activesupport (4.2.1) lib/active_support/callbacks.rb:506:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_create_callbacks'
activerecord (4.2.1) lib/active_record/callbacks.rb:306:in `_create_record'
activerecord (4.2.1) lib/active_record/timestamp.rb:57:in `_create_record'
activerecord (4.2.1) lib/active_record/persistence.rb:502:in `create_or_update'
我已阅读 Google Compute Engine 网站上关于 Sending Emails 的文档,发现端口 25 上的传出被阻止,因此我使用 2525。我也尝试使用 :2525 和 :plain 而不是 '2525' 和 '在我的 staging.rb 中的 ActionMailer 设置中使用plain'。这可能是什么问题?
请帮忙 谢谢你
【问题讨论】:
-
您有没有机会查看实例防火墙 (iptables..) 以检查端口是否被阻止?
标签: ruby-on-rails-4 nginx passenger google-compute-engine sendgrid