无法使用gmail smtp服务器发送邮件(在话语中)

时间:2013-03-01 03:22:14

标签: ruby-on-rails smtp gmail discourse

我正在尝试设置discourse,这是一个rails3 webapp,但在使用gmail smtp服务器配置smtp时遇到一些问题。

我昨天注册了一个新的Gmail帐户,我可以登录浏览器和电子邮件客户端软件。

然后我在文件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
}

启动用于在后台发送邮件的sidekiq

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

然后在制作模式中开始讨论:

rails server -e production -d

但它不起作用。我可以在sidekiq.log中看到一些错误:

  

2013-03-01T03:06:02Z 30687 TID-qib28警告:{“retry”=> true,“queue”=>“default”,“class”=>“Jobs :: UserEmail”, “args”=> [{“type”=>“注册”,“user_id”=> 42,“email_token”=>“b40a21ece2b14586e346abfd96685975”,“current_site_id”=>“默认”}],“jid “=>”558bb6bd5aa36cfc8d3d1e91“,”error_message“=>”拒绝连接 - 连接(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警告:连接被拒绝 - 连接(2)   2013-03-01T03:06:02Z 30687 TID-qib28警告:/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开放”   /home/discourse/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/net/smtp.rb:540:in`tcp_socket'

我尝试过各种smtp设置,但都没有。


更新

Per @ Basil的答案,我刚试过:

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
}

但它有同样的错误。域shuzu.org是我网站的域名,我以为我应该将其传递给smtp。现在我删除了它,但仍然没有工作。

5 个答案:

答案 0 :(得分:5)

最后,我找到了(愚蠢的)理由。

我应该在生产模式下启动sidekiq

nohup bundle exec sidekiq -e production > log/sidekiq.log 2>&1 &

答案 1 :(得分:2)

尝试删除端口周围的引号

  :port      => 587,

此外,我不明白为什么您的电子邮件地址是@gmail,但您的域名是@shuhzu ... smtp设置应显示您的电子邮件帐户的域名。如果您有自定义Gmail,即me@custom.com,那么域名将是custom.com。以下是您拥有自定义电子邮件地址时域名的smtp设置的示例:

{
    :address => "smtp.gmail.com",
    :port => 587 ,
    :domain => "custom.com",
    :user_name => "some_email@custom.com",
    :password => "some_password",
    :authentication => "plain",
    :enable_starttls_auto => true
}

答案 2 :(得分:1)

有时在<input type="button" class="button-clickers" value="Bnt1"> <input type="button" class="button-clickers" value="Bnt2"> <input type="button" class="button-clickers" value="Bnt3"> <input type="button" class="button-clickers" value="Bnt4"> <input type="button" class="button-clickers" value="Bnt5"> <input type="button" class="button-clickers" value="Bnt6"> <input type="button" class="button-clickers" value="Bnt7">中取消注释以下行很有用:

tableView.delegate = self
tableView.dataSource = self

您应该在此处放置所有Discourse电子邮件所代表的地址。默认情况下,Discourse会尝试使用您论坛的域名,但是您的SMTP可能不允许使用。例如,您的论坛位于/var/discourse/containers/app.yml,而您的Gmail SMTP仅允许来自 ## 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'" 的电子邮件。

对于没有身份验证的SMTP,只需保留以下身份验证字段即可:

forum.example.com

在保存所有内容之后:

example.com

电子邮件正常工作后,您可以重新注释此行(使用 DISCOURSE_SMTP_USER_NAME: DISCOURSE_SMTP_PASSWORD: )。

您甚至可以只通过控制台设置此./launcher rebuild app ,但比取消注释/重新注释一行并重新构建容器要困难得多,因此我将不对其进行详细说明。

答案 3 :(得分:0)

在我的安装中,这是一个预先制作的图像内容(Bitnami),我只需要运行它:

/opt/discourse-0.9.5-0/ctlscript.sh start discourse_sidekiq

任何人都知道如何自动执行此操作以便在启动时发生?

答案 4 :(得分:0)

我只是在我自己的ubuntu物理站点服务器上的docker容器中设置了一个新的话语实例,并编辑了app.yml以包含:

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

它有效。一半的战斗是知道在哪里放置单引号(')和不在哪里。

我也可以使用另一种方式 - 我的ISP为其静态IP客户提供了一个中继smtp,所以我在app.yam中使用了这个:

DISCOURSE_SMTP_ADDRESS: mail.myisp.tld
DISCOURSE_SMTP_AUTHENTICATION: none
DISCOURSE_SMTP_PORT: 25

它也适用于我。

相关问题