Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't send mail with gmail smtp server (in discourse)

I'm trying to setup discourse, which is a rails3 webapp, but have some problems configuring smtp with gmail smtp server.

I have registered a new gmail account yesterday, and I can logged in browser and email-client software.

Then I configure discourse, in the file config/environments/production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address   => "smtp.gmail.com",
  :port      => "587",
  :user_name => "[email protected]",
  :password  => "12345678",
  :authentication => :plain,
  :domain => "shuzhu.org",
  :enable_starttls_auto => true
}

Start the sidekiq which is used to sending the mails in the background:

nohup bundle exec sidekiq > log/sidekiq.log 2>&1 &

Then start discourse in production mode:

rails server -e production -d

But it doesn't work. I can see some errors in sidekiq.log:

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 initialize' /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:inopen' /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in `tcp_socket'

I have tried all kinds of smtp settings, but none of them works.


UPDATE:

Per @Basil's answer, I just tried:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address   => "smtp.gmail.com",
  :port      => 587,
  :user_name => "smtp4shuzu",
  :password  => "12345678",
  :authentication => "plain",
  :enable_starttls_auto => true
}

But it has the same error. The domain shuzu.org is the domain of my site, I was thinking I should passing it to smtp. Now I removed it, but still not working.

like image 718
Freewind Avatar asked Jan 15 '23 01:01

Freewind


1 Answers

At last, I found the (stupid) reason.

I should start sidekiq in production mode:

nohup bundle exec sidekiq -e production > log/sidekiq.log 2>&1 &
like image 55
Freewind Avatar answered Jan 19 '23 11:01

Freewind