title: Sendgrid via Devise: Attempt to send authentication email leads to OpenTimeout error when using Cloud 9 dev environment
body: <p>I'm relatively new to programming and very new to web development and have been working my way through a Ruby on Rails bootcamp over the past few weeks. The current step I'm on involves adding user authentication to my site using Devise, but I'm getting a "silent error" where the authentication email won't send.</p>
  
  <p>In line with the guide I'm following as part of the bootcamp, I've gone through the following steps:</p>
  
  <ol>
  <li>Installed the Devise gem</li>
  <li><p>Configured it by appending the following to my development.rb file:</p>
  
  <pre><code>...
      config.action_mailer.default_url_options = { host: 'localhost:3000' }
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.perform_deliveries = true
      config.action_mailer.raise_delivery_errors = true
  end
  </code></pre></li>
  <li><p>Created a user model using devise before updating the [timestamp]_devise_create_users.rb file to include the confirmable option.</p></li>
  <li><p>Ran rake db:migrate</p></li>
  <li><p>Added the Sendgrid addon (confirmed using "heroku addon")</p></li>
  <li><p>Created a setup_mail.rb initializer with the following code:</p>
  
  <pre><code>if Rails.env.development?
      ActionMailer::Base.delivery_method = :smtp
      ActionMailer::Base.smtp_settings = {
          address:        'smtp.sendgrid.net',
          port:           '587',
          authentication: :plain,
          user_name:      ENV['SENDGRID_USERNAME'],
          password:       ENV['SENDGRID_PASSWORD'],
          domain:         'heroku.com',
          enable_starttls_auto: true
      }
  end
  </code></pre></li>
  <li><p>Installed the Figaro gem</p></li>
  <li>Added SENDGRID_USERNAME &amp; SENDGRID_PASSWORD to application.yml</li>
  <li>Set <code>production: SECRET_KEY_BASE</code> to a randomly generated token within secrets.yml</li>
  </ol>
  
  <p>Within Dev mode, the app now successfully loads the user sign-up form, but after signing up an authentication email is not sent. The following error is instead generated:</p>
  
  <p><code>Net::OpenTimeout in Devise::RegistrationsController#create</code> </p>
  
  <p>I've looked around and <a href="https://docs.c9.io/v1.0/discuss/55034a464731190d00360648" rel="nofollow">it seems a few other people have reported the same error when using Cloud 9</a> but none have offered suggestions on how to resolve the problem. My (somewhat uneducated) theory is that the host setting in development.rb needs to be different or the port in setup_mail.rb needs to be different as I'm using the C9 service instead of a local machine - but I'm not sure how to find out what these should be set to (if indeed that is the problem).</p>
  
  <p>So far I've tried</p>
  
  <ul>
  <li>Changing localhost to 8080 in development.rb (this is the port which c9 seems to use based on text in the terminal)</li>
  <li>Changing setup_mail.rb domain to sendgrid.com</li>
  <li>Ensuring Sendgrid account was not blocked for any reason</li>
  </ul>
  
  <p>My User.rb file currently looks like this</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      # Include default devise modules. Others available are:
      # :confirmable, :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable,
             :recoverable, :rememberable, :trackable, :validatable, :confirmable
  end
  </code></pre>
  
  <p>Can anyone give me a clue as to what's going on?</p>