Not able to send eamil from heroku console - ruby-on-rails

I am trying to send email using SMTP server onheroku run rails console but getting some error. But it is working absolutely fine on local system, not able to understand what's the problem.
Code:
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
Error: when run the above code on heroku console
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>'

It appears based on your call heroku run rails console, that you are trying to run this on a Heroku based server. According to Heroku's own docs, you are only allowed to send email using an external service, such as SendGrid or other providers.

Related

Pry on the production server - how can I make it work there?

I can debug an app locally with binding.pry just fine. But I need to that on the remote server (webiste) as well, because locally I don't have any error but on production I do. So put binding.pry in the source file on the server and when I made a post request to the website, I didn't return any response and even when I ran rails console on the server didn't change anything and there was no output in rails console.
It's a dev server, so it's visible in the internet but it's a developer server, although for rails it's production because RAIL_ENV is equal to production. I really need to debug it the way I can do locally using pry. How can I do it?
update:
# bundle exec pry-remote
/usr/lib/ruby/1.9.1/drb/drb.rb:736:in `rescue in block in open': druby://127.0.0.1:9876 - #<Errno::ECONNREFUSED: Connection refused - connect(2)> (DRb::DRbConnError)
from /usr/lib/ruby/1.9.1/drb/drb.rb:730:in `block in open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:729:in `each'
from /usr/lib/ruby/1.9.1/drb/drb.rb:729:in `open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1191:in `initialize'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1171:in `new'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1171:in `open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/gems/pry-remote-0.1.8/lib/pry-remote.rb:289:in `run'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/gems/pry-remote-0.1.8/bin/pry-remote:4:in `<top (required)>'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/bin/pry-remote:19:in `load'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/bin/pry-remote:19:in `<main>'
I assume your production app is run by some kind of daemonized application server, such as Puma or Unicorn.
In this setup, pry-remote can help.
add it to your Gemfile
use binding.remote_pry instead of binding.pry
execute bundle exec pry-remote on your server
You'll get a pry shell as soon as the breakpoint has been hit.

NetSSh Gem , Start method producing Connection TimedOut Error

In my Project, I'm testing the connection with remote Windows 2008 server, through ssh. I'm always getting the following error:
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `initialize'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `open'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:70:in `block in initialize'
from /home/kamesh/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
from /home/kamesh/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/timeout.rb:97:in `timeout'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:67:in `initialize'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `new'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `start'
from /home/kamesh/projects/RubyApp/lib/connections/ssh_connection.rb:9:in `connect'
from (irb):5
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start'
from /home/kamesh/.rvm/gems/ruby-2.0.0-p353/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
To ensure, what we're talking about the same thing - here's a link to Net::SSH GitHub page.
According to your error message, your ssh client can't connect to ssh server on another host.
First, you need to ensure that your server has server running. Here's a guide about how to install it on Windows Server 2008.
Second, you need to try and ping your server, to ensure if it's accessible through your network at all.
If there weren't any problems on previous stages, you can try to use Net::SSH again.

Unable to run console on Heroku

I'm trying to deploy my app on a Heroku server, but for some reason I can neither start my app nor run console. When I try to execute heroku run console, I get the following:
MacBook:threexortwo lander$ heroku run console
Running `console` attached to terminal... up, run.1
Rubber[ERROR]: Unable to read rubber configuration from /app/config/rubber/rubber.yml
(erb):301:in `<main>': undefined local variable or method `rubber_env' for main:Object (NameError)
from /usr/local/lib/ruby/1.9.1/erb.rb:753:in `eval'
from /usr/local/lib/ruby/1.9.1/erb.rb:753:in `result'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/environment.rb:39:in `read_config'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/environment.rb:30:in `block in initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/environment.rb:30:in `each'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/environment.rb:30:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/configuration.rb:37:in `new'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/configuration.rb:37:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/configuration.rb:14:in `new'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/configuration.rb:14:in `get_configuration'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/configuration.rb:22:in `rubber_env'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber.rb:53:in `config'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber.rb:31:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/rubber-2.1.2/lib/rubber/railtie.rb:9:in `block in <class:Railtie>'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `call'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:67:in `inherited'
from /app/config/application.rb:13:in `<module:Threexortwo>'
from /app/config/application.rb:12:in `<top (required)>'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:39:in `require'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:39:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Previously, I was playing with an Amazon EC2 server, and was using rubber. Before doing anything with rubber, I created a backup (pretty much just zipped the project), then afterwards deleted the vulcanized version, restored the old one, and uninstalled `rubber. When I run my server app locally, I don't encounter this issue, and I only get it when messing with Heroku.
It looks like rubber is still in your gemfile. Heroku reads in your gemfile and installs all of the gems listed.
Try removing it.

How do I fix a "Connection timed out" error for HTTP read operations on Heroku?

I have an operation in my Heroku-hosted Rails app that runs in a background process and calls out to a government website that is slow. I am receiving a timeout error (at the bottom below) that I haven't been able to fix.
The read timeout appears happen at 20 seconds into the request.
The following line causes the problem:
Mechanize.new.get('http://ai.fmcsa.dot.gov/SMS/Data/Search.aspx')
Is there an environment variable that fixes this? Something else that I'm missing?
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `open'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `block in connect'
from /usr/local/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /usr/local/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `connect'
from /usr/local/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from /usr/local/lib/ruby/1.9.1/net/http.rb:632:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:768:in `reset'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:503:in `connection_for'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:806:in `request'
from /app/vendor/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:258:in `fetch'
from /app/vendor/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize.rb:407:in `get'
from /app/app/models/inspection.rb:14:in `fmcsa_summary'
from (irb):5
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
The solution that worked as a temporary fix was to use a proxy server via Mechanize. There must be something going on between the server that I'm connecting to and the IP address range of the Heroku EC2 instances.
agent = Mechanize.new { |a| a.set_proxy(url,port,username,password) }
It would still be helpful if someone knew the root cause of the original problem.

Pandastream heroku error

I have followed the pandastream setup docs on Heroku, available here https://devcenter.heroku.com/articles/pandastream
However when using heroku run console and executing Panda::Profile.all I get
irb(main):001:0> Panda::Profile.all
NoMethodError: undefined method `connection' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/cloud_connection.rb:4:in `connection'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:19:in `find_object_by_path'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:23:in `find_by_path'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:44:in `all'
from (irb):1
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Testing it locally works fine with the intended results. Any ideas?
Some sanity checks
Did you create the file config/initializers/panda.rb as given in guide for initializer?
Run heroku addons:open pandastream & verify your S3 bucket and credentials. a wrong credential will most likely lead to connection error like you are seeing in your stack trace
try update to the latest version of typhoeus & panda to see if that helps
Hope it helps. And don't forget to Post back, if none of this helps.

Resources