0

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>'
Ajay Gupta
  • 192
  • 1
  • 12
  • http://stackoverflow.com/questions/16040158/rails-mailer-netopentimeout-execution-expired-exception-on-production-serve – Rajarshi Das Oct 01 '15 at 12:23

1 Answers1

0

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.

Josh
  • 338
  • 3
  • 14