Ruby-on-rails 如何在 Gitlab 上调试电子邮件发送?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16125623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 21:50:50  来源:igfitidea点击:

How can I debug e-mail sending on Gitlab?

ruby-on-railsrubygitlab

提问by André Puel

My Gitlab (version 5) is not sending any e-mails and I am lost trying to figure out what is happening. The logs give no useful information. I configured it to used sendmail.

我的 Gitlab(版本 5)没有发送任何电子邮件,我无法弄清楚发生了什么。日志没有提供有用的信息。我将其配置为使用sendmail.

I wrote a small script that sends e-mail through ActionMailer (I guess it is what gitlab uses to send e-mail, right?). And it sends the e-mail correctly.

我写了一个通过 ActionMailer 发送电子邮件的小脚本(我猜这是 gitlab 用来发送电子邮件的,对吧?)。它正确发送电子邮件。

But, on my Gitlab, I can guarantee that sendmail is not even being called.

但是,在我的 Gitlab 上,我可以保证甚至不会调用 sendmail。

Do I need to enable something to get e-mail notifications? How can I debug my issue?

我是否需要启用某些功能才能接收电子邮件通知?如何调试我的问题?

Update

更新

The problem is that I can not find any information anywhere. The thing just fails silently. Where can I find some kind of log? The logs in the logdir provide no useful information.

问题是我在任何地方都找不到任何信息。事情只是默默地失败了。我在哪里可以找到某种日志?log目录中的日志没有提供有用的信息。

My question is, how can I make Gitlab be more verbose? How can I make it tell me what is going on?

我的问题是,如何让 Gitlab 变得更冗长?我怎样才能让它告诉我发生了什么?

Update 2

更新 2

I just found a lot of mails scheduled on the Background jobssection. A lot of unprocessed Sidekiq::Extensions::DelayedMailer. What does it mean? Why were these jobs not processed?

我刚刚发现该Background jobs部分安排了很多邮件。很多未加工Sidekiq::Extensions::DelayedMailer。这是什么意思?为什么这些作业没有被处理?

采纳答案by André Puel

First, I will tell what was my problem: The sidekiq is responsible for handling sending e-mails. For some reason my sidekiq was stuck, restarting it solved the problem.

首先,我将说明我的问题是什么:sidekiq 负责处理发送电子邮件。由于某种原因,我的 sidekiq 卡住了,重新启动它解决了问题。

Where I found information about problems I found on Gitlab:

我在哪里找到了有关我在 Gitlab 上发现的问题的信息:

  1. The logs dir. It has a few informations.
  2. On admin page, the section "Background jobs" gives information about the sidekiq.
  3. The javascript console (if your browser supports it) also has useful information. Only if your problem is related to javascript.
  4. And if you reach this point, you may modify Gitlab's code so you can "trace it" writing to a file:

    File.open('/tmp/logfile','a') { |file| file.write("Hello World!\n") }

  1. 日志目录。它有一些信息。
  2. 在管理页面上,“后台作业”部分提供了有关 sidekiq 的信息。
  3. javascript 控制台(如果您的浏览器支持)也有有用的信息。仅当您的问题与 javascript 相关时。
  4. 如果你到了这一步,你可以修改 Gitlab 的代码,这样你就可以“跟踪”写入文件:

    File.open('/tmp/logfile','a') { |file| file.write("Hello World!\n") }

回答by pixelbrackets

Stumbled upon this issue today, here's my research:

今天偶然发现这个问题,这是我的研究:

Debugging SMTP connections in the GitLab GUI is not supported yet. However there is a pending feature requestand a command line solution.

尚不支持在 GitLab GUI 中调试 SMTP 连接。但是,有一个待处理的功能请求和一个命令行解决方案

Set the desired SMTP settings /etc/gitlab/gitlab.rband run gitlab-ctl reconfigure(see https://docs.gitlab.com/omnibus/settings/smtp.html).

设置所需的 SMTP 设置/etc/gitlab/gitlab.rb并运行gitlab-ctl reconfigure(请参阅https://docs.gitlab.com/omnibus/settings/smtp.html)。

Start the console running gitlab-rails console production.

启动控制台运行gitlab-rails console production

Show the configured delivery method (should be :smtp) running the command ActionMailer::Base.delivery_method. Show all configured SMTP settings running ActionMailer::Base.smtp_settings.

显示配置的传送方式(应该是:smtp)运行命令ActionMailer::Base.delivery_method。显示所有已配置的 SMTP 设置正在运行ActionMailer::Base.smtp_settings

To send a test mail run

发送测试邮件运行

Notify.test_email('[email protected]', 'Hello World', 'This is a test message').deliver_now

On the admin page in GitLab, the section ?Background jobs? shows information about all jobs. Failing SMTP connections are listed there as well.

在 GitLab 的管理页面上,“后台工作”部分?显示有关所有作业的信息。那里也列出了失败的 SMTP 连接。

Please note, you may need to restart the GitLab instance in order to use the newly configured SMTP settings (on my instance the console was able to send mails, the GUI required a restart). Run gitlab-ctl restartto restart your instance.

请注意,您可能需要重新启动 GitLab 实例才能使用新配置的 SMTP 设置(在我的实例中,控制台能够发送邮件,GUI 需要重新启动)。运行gitlab-ctl restart以重新启动您的实例。

回答by Intrepidd

Maybe try enabling delivery errors in production mode and see what happens

也许尝试在生产模式下启用交付错误,看看会发生什么

  config.action_mailer.raise_delivery_errors = true

回答by VertigoRay

I had the same problem and found that I needed to mod application.rb:

我遇到了同样的问题,发现我需要修改 application.rb:

diff --git a/config/application.rb b/config/application.rb
index d85bcab..274976f 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -11,6 +11,8 @@ end

 module Gitlab
   class Application < Rails::Application
+    config.action_mailer.sendmail_settings = { :arguments => "-i" }
+
     # Settings in config/environments/* take precedence over those specified here.
     # Application configuration should go into files in config/initializers
     # -- all .rb files in that directory are automatically loaded.

Note: I'm running Debian 7 which uses exim for mail.

注意:我正在运行 Debian 7,它使用 exim 进行邮件处理。

回答by bbodenmiller

In the admin section under Background Jobs if you have lots of items in the Scheduled tab try restarting sidekiq:

在后台作业下的管理部分,如果计划选项卡中有很多项目,请尝试重新启动sidekiq

cd /home/git/gitlab    
exec rake sidekiq:start RAILS_ENV=production