问题
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 => "smtp4shuzu@gmail.com",
: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:in
open' /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.
回答1:
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 &
回答2:
Try removing the quotes around the port
:port => 587,
Also, I don't understand why your email address is @gmail but your domain is @shuhzu... smtp settings should show the domain for your email account. If you have a custom gmail, i.e me@custom.com then domain would be custom.com. Here is an example of what smtp settings for your domain should be if you have a custom email address:
{
:address => "smtp.gmail.com",
:port => 587 ,
:domain => "custom.com",
:user_name => "some_email@custom.com",
:password => "some_password",
:authentication => "plain",
:enable_starttls_auto => true
}
回答3:
Sometimes it is useful to uncomment the following line in /var/discourse/containers/app.yml
:
## If you want to set the 'From' email address for your first registration, uncomment and change:
## After getting the first signup email, re-comment the line. It only needs to run once.
- exec: rails r "SiteSetting.notification_email='noreply@YOURDOMAIN.com'"
You should put here the address on behalf of which all Discourse's emails should come. By default Discourse will try to use your forum's domain name, but it may not be allowed by your SMTP. For example, your forum is at forum.example.com
, while your Gmail SMTP only allows emails from example.com
.
For SMTP without authentication just leave the auth fields like this:
DISCOURSE_SMTP_USER_NAME:
DISCOURSE_SMTP_PASSWORD:
and after everything is saved:
./launcher rebuild app
Once emails are working, you can re-comment this line (with SiteSetting
).
You can even just set this SiteSetting
via console, but it's more difficult than uncommenting/re-commenting a single line and re-build the container, so I'll not elaborate on this.
回答4:
On my install, which is one of those pre-made image thingies (Bitnami), I just had to run this:
/opt/discourse-0.9.5-0/ctlscript.sh start discourse_sidekiq
Anyone know how I can automate this so that it happens on startup?
回答5:
I just set up a new discourse instance in a docker container on my own ubuntu physical on site server and edited the app.yml to contain:
DISCOURSE_SMTP_ADDRESS: 'smtp.gmail.com'
DISCOURSE_SMTP_AUTHENTICATION: 'plain'
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: 'my.name@gmail.com'
DISCOURSE_SMTP_PASSWORD: 'myPa$$word'
DISCOURSE_SMTP_ENABLE_START_TLS: true
and it worked. Half the battle was knowing where to put single inverted commas (') and where not to.
Another way was available to me also - my ISP provides a relay smtp for it's static IP customers so I used this in app.yam:
DISCOURSE_SMTP_ADDRESS: mail.myisp.tld
DISCOURSE_SMTP_AUTHENTICATION: none
DISCOURSE_SMTP_PORT: 25
and it works for me also.
来源:https://stackoverflow.com/questions/15149942/cant-send-mail-with-gmail-stmp-server-in-discourse