GitLab邮件通知未发送

14

我最近在Ubuntu 12.04服务器上安装了GitLab v5.0,现在遇到了有关电子邮件通知的问题。我无法让GitLab发送任何类型的电子邮件。

我已经配置了我的config/environments/production.rb文件,以使用sendmail作为传输服务:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

我可以按照这里描述的方式手动在shell中使用sendmail发送邮件:http://scratching.psybermonkey.net/2011/03/sendmail-how-to-test-sending-email.html

我的config/gitlab.yml文件已配置以下电子邮件设置:

email_from: gitlab@myops.com

我看到说这可能是Sidekiq没有运行的问题,所以我运行了以下命令,但仍然无法发送电子邮件:

$ sudo -u git -H bundle exec rake sidekiq:start RAILS_ENV=production
$ ps aux |grep -i sidekiq
git       2791  2.1  4.2 206476 86620 pts/0    Sl   14:45   0:23 sidekiq 2.7.5 gitlab [0 of 25 busy] 

这表明Sidekiq确实在运行...还有什么其他问题吗?不幸的是,GitLab的维基上似乎没有太多关于电子邮件设置的文档...

我在sidekiq.log中发现了以下错误记录:

2013-04-24T21:09:01Z 2791 TID-1jaur8 Sidekiq::Extensions::DelayedMailer JID-21bd3ec0f086351088992396 INFO: start
2013-04-24T21:09:01Z 2791 TID-1jaur8 Sidekiq::Extensions::DelayedMailer JID-21bd3ec0f086351088992396 INFO: fail: 0.004 sec
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: {"retry"=>true, "queue"=>"default", "timeout"=>30, "class"=>"Sidekiq::Extensions::DelayedMailer", "args"=>["---\n- !ruby/class 'Notify'\n- :new_user_email\n- - 4\n - pSzzULp8\n"], "at"=>1366819034.5969028, "jid"=>"21bd3ec0f086351088992396", "error_message"=>"Couldn't find User with id=4", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>"2013-04-24T15:57:19Z", "retry_count"=>10, "retried_at"=>2013-04-24 21:09:01 UTC}
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: Couldn't find User with id=4
2013-04-24T21:09:01Z 2791 TID-1jaur8 WARN: /home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:343:in `find_one'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:314:in `find_with_ids'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:107:in `find'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/querying.rb:5:in `find'
/home/git/gitlab/app/mailers/notify.rb:23:in `new_user_email'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:459:in `process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:453:in `initialize'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:439:in `new'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:439:in `method_missing'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/extensions/action_mailer.rb:20:in `perform'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:45:in `block (3 levels) in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:109:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:109:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/timeout.rb:11:in `block in call'
/usr/local/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/timeout.rb:10:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/active_record.rb:6:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/retry_jobs.rb:49:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/logging.rb:11:in `block in call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/logging.rb:22:in `with_context'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/server/logging.rb:7:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:111:in `block in invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:114:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/middleware/chain.rb:114:in `invoke'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:44:in `block (2 levels) in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:80:in `stats'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.7.5/lib/sidekiq/processor.rb:43:in `block in process'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `public_send'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/calls.rb:23:in `dispatch'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/future.rb:18:in `block in initialize'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/internal_pool.rb:48:in `call'
/home/git/gitlab/vendor/bundle/ruby/1.9.1/gems/celluloid-0.12.4/lib/celluloid/internal_pool.rb:48:in `block in create'

有什么想法吗?

我不确定这是否是Gitlab问题的正确媒介,因为它与编程没有直接关系。但是就此而言,我建议通过Web浏览器检查/admin/logs,看看是否有任何随机错误与SideKiq相关或者是否有作业失败的情况。同时,请查看服务器上Gitlab应用程序根目录中的log目录。 - Steven V
根据sidekiq.log文件中的发现,似乎之前已经讨论过这种类型的事情了,链接在这里:https://github.com/gitlabhq/gitlabhq/issues/2747 不幸的是,我没有看到解决方案... 我会更新我的OP以包含sidekiq.log文件的相关部分。 - sadmicrowave
sidekiq.log文件中有完全相同的条目,我记得做了一些事情来解决它...但我不记得是什么了。现在已经过去一个多月了。 Bash历史记录也没有帮助到我。 - Steven V
这真让我崩溃,我对GitLab设置电子邮件通知的文档缺乏有些失望。这个功能似乎非常重要... - sadmicrowave
2个回答

8

这是我在 /config/environment/production.rb 文件末尾添加的条目,对我有效。


注释掉 sendmail 选项,使用外部 SMTP 中继

  ##config.action_mailer.delivery_method = :sendmail ## Comment out this
  # Defaults to:
  ## config.action_mailer.sendmail_settings = {
  ##   :location => '/usr/sbin/sendmail',
  ##   :arguments => '-i -t'
  ## }

  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  ## SMTP Settings
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address => '10.146.10.90', ## My SMTP Relay/Gateway
      :port => 25, ## SMTP Port
      :domain => 'gitlab.example.com', ## My Domain
      :authentication => :plain, ## Let it be plain as it is inside my LAN
      ##:user_name => 'gitlab@yourserver.com', ## This is not required as long as 
      ##:password => 'yourPassword', ## SMTP Gateway allows anonymous relay
      ##:enable_starttls_auto => true ## In LAN
      ##:user_name => '',
      ##:password => '',
      :enable_starttls_auto => true
  }
end


谢谢您的评论!我实现了与您相同的配置,信不信由你,我收到了一封添加用户的电子邮件(我添加了一个用于测试的辅助电子邮件)。但这只发生了一次,现在即使我在gitlab中删除帐户并重新添加它,我也无法发送任何邮件...很奇怪。 - sadmicrowave
1
这个配置文件在哪里可以找到? - Leandro Garcia
默认情况下,它是/home/git/gitlab/config/environments/production.rb - ihsan
作为一个新的GitLab用户,我很好奇我们应该在什么情况下编辑这个文件,而在什么情况下应该编辑/ etc / gitlab / gitlab.rb文件。@sadmicrowave - 我也遇到了同样的问题。刚开始设置时可以工作,现在却神秘地不行了。我现在看到远程邮件服务器记录了来自我的GitLab服务器的匿名登录尝试,而不是通过用户名发送。 - unc0nnected
更新:将以下内容添加到我的production.rb文件中导致我的Web界面完全崩溃,并在所有页面上显示502错误。 - unc0nnected
我眼里有泪水。 - xeed

3
在CentOS上,这对我有帮助:
检查你的文件 /home/git/gitlab/config/environments/production.rb(如果你正在运行生产环境,这是标准的)。
在那里可以更改你的sendmail设置。你应该尝试删除 -t 参数,这对我有用!一些邮件服务器不接受这个参数(检查你的邮件日志以确保)。
  config.action_mailer.sendmail_settings = {
    :location => '/usr/sbin/sendmail',
    :arguments => '-i'
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接