title: Mail not send via send grid mailing service
body: <p>We have been using send grid mailing service on our rails app to send mail to our users. We have our app hosted on <code>Heroku</code> server, but there is an internal error as soon as rails try to send email to our users.</p>
  
  <p>I looked into Heroku Logs and the error is</p>
  
  <blockquote>
    <p>Completed 500 Internal Server Error in 63ms (ActiveRecord:
    11.1ms)2017-08-24T11:28:03.914063+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 25):</p>
  </blockquote>
  
  <p>In production.rb</p>
  
  <pre><code>config.action_mailer.delivery_method = :smtp
  
  config.action_mailer.perform_deliveries = true
  
  config.action_mailer.smtp_settings = {
    :user_name =&gt; ENV['SENDGRID_USERNAME'],
    :password =&gt; ENV['SENDGRID_PASSWORD'],
    :domain =&gt; ENV['DOMAIN'],
    :address =&gt; 'smtp.sendgrid.net',
    :port =&gt; 587,
    :authentication =&gt; :plain,
    :enable_starttls_auto =&gt; true
  }
  </code></pre>
  
  <p>We have used <code>SendGrid heroku</code> add-on on the server so <code>ENV</code> are setup fine.
  The <code>domain: ENV['DOMAIN']</code> points to domain setup on <code>ENV</code> Variable as the domain will be different on a staging server and production server.</p>