无法从heroku控制台发送eamil

时间:2015-10-01 11:16:45

标签: ruby-on-rails heroku

我正在SMTP上使用heroku run rails console服务器发送电子邮件,但收到了一些错误。但它在本地系统上工作得非常好,无法理解问题所在。

代码:

message = <<MESSAGE_END
From: Jobs<notification@example.com>
To: Ajay Gupta<ajaygupta@example.com>
Subject: SMTP e-mail test

This is a test e-mail message.
MESSAGE_END

Net::SMTP.start('SMTP_URL') do |smtp|
  smtp.send_message 'message', 'ajaygupta@example.com', 'ajaygupta@example.com'
end

错误:在heroku控制台上运行上面的代码时

Net::OpenTimeout: execution expired
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `initialize'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `open'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `tcp_socket'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:551:in `block in do_start'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:550:in `do_start'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:520:in `start'
        from /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:457:in `start'
        from (irb):3
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
        from /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
        from /app/bin/rails:4:in `require'
        from /app/bin/rails:4:in `<main>'

1 个答案:

答案 0 :(得分:0)

根据您的呼叫heroku run rails console显示您尝试在基于Heroku的服务器上运行此功能。根据Heroku自己的docs,您只能使用外部服务发送电子邮件,例如SendGrid或其他提供商。