title: Can't send mail with gmail smtp server (in discourse)
body: <p>I'm trying to setup <a href="http://www.discourse.org" rel="nofollow">discourse</a>, which is a rails3 webapp, but have some problems configuring smtp with gmail smtp server.</p>
  
  <p>I have registered a new gmail account yesterday, and I can logged in browser and email-client software.</p>
  
  <p>Then I configure discourse, in the file <code>config/environments/production.rb</code>:</p>
  
  <pre><code>config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address   =&gt; "smtp.gmail.com",
    :port      =&gt; "587",
    :user_name =&gt; "smtp4shuzu@gmail.com",
    :password  =&gt; "12345678",
    :authentication =&gt; :plain,
    :domain =&gt; "shuzhu.org",
    :enable_starttls_auto =&gt; true
  }
  </code></pre>
  
  <p>Start the <code>sidekiq</code> which is used to sending the mails in the background:</p>
  
  <pre><code>nohup bundle exec sidekiq &gt; log/sidekiq.log 2&gt;&amp;1 &amp;
  </code></pre>
  
  <p>Then start discourse in production mode:</p>
  
  <pre><code>rails server -e production -d
  </code></pre>
  
  <p>But it doesn't work. I can see some errors in <code>sidekiq.log</code>:</p>
  
  <blockquote>
    <p>2013-03-01T03:06:02Z 30687 TID-qib28 WARN: {"retry"=>true, "queue"=>"default", "class"=>"Jobs::UserEmail", "args"=>[{"type"=>"signup", "user_id"=>42, "email_token"=>"b40a21ece2b14586e346abfd96685975", "current_site_id"=>"default"}], "jid"=>"558bb6bd5aa36cfc8d3d1e91", "error_message"=>"Connection refused - connect(2)", "error_class"=>"Errno::ECONNREFUSED", "failed_at"=>2013-03-01 03:06:02 UTC, "retry_count"=>0}
    2013-03-01T03:06:02Z 30687 TID-qib28 WARN: Connection refused - connect(2)
    2013-03-01T03:06:02Z 30687 TID-qib28 WARN: /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in <code>initialize'
    /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in</code>open'
    /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'</p>
  </blockquote>
  
  <p>I have tried all kinds of smtp settings, but none of them works.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>Per @Basil's answer, I just tried:</p>
  
  <pre><code>config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address   =&gt; "smtp.gmail.com",
    :port      =&gt; 587,
    :user_name =&gt; "smtp4shuzu",
    :password  =&gt; "12345678",
    :authentication =&gt; "plain",
    :enable_starttls_auto =&gt; true
  }
  </code></pre>
  
  <p>But it has the same error. The domain <code>shuzu.org</code> is the domain of my site, I was thinking I should passing it to smtp. Now I removed it, but still not working.</p>