Ruby-on-rails GitLab 电子邮件设置:通过另一个邮件服务器发送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10690255/
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
GitLab email setup: sending via another mail server
提问by el_quick
By default gitlab has the next configuration in gitlab.yml:
默认情况下,gitlab 具有以下配置gitlab.yml:
email:
from: [email protected]
host: gitlabhq.com
but, I need to specify other variables (host, port, user, password, etc) to use another mail server.
但是,我需要指定其他变量(主机、端口、用户、密码等)才能使用另一个邮件服务器。
How I do that?
我怎么做?
采纳答案by Joshua
This confused me too. But to change the mail setting you edit them in config/environments/production.rb Just add a config.action_mailer.smtp_settings like a regular rails app.
这也让我很困惑。但是要更改邮件设置,您可以在 config/environments/production.rb 中编辑它们,只需像常规 Rails 应用程序一样添加 config.action_mailer.smtp_settings 即可。
回答by Girish KG
Now it is totally different in Gitlab 5.2+.
现在它在 Gitlab 5.2+ 中完全不同。
It is in "/home/git/gitlab/config/initializers/smtp_settings.rb.sample" and we just need to follow the instructions in that.
它在“/home/git/gitlab/config/initializers/smtp_settings.rb.sample”中,我们只需要按照其中的说明进行操作。
回答by Adrian
Note: This method was useful for older versions of Gitlab. See the answerof Girish for newer versions.
注意:此方法对于旧版本的 Gitlab 很有用。有关较新版本,请参阅Girish的答案。
At the end of config/environments/production.rb you can add something like this:
在 config/environments/production.rb 的末尾,您可以添加如下内容:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'yourserver.com',
:port => 25,
:domain => 'gitlab.yourserver.com',
:authentication => :plain,
:user_name => '[email protected]',
:password => 'yourPassword',
:enable_starttls_auto => true
}
Refer to the ActionMailer documentation for a more detailed description of possible configurations: http://api.rubyonrails.org/classes/ActionMailer/Base.html
有关可能的配置的更详细说明,请参阅 ActionMailer 文档:http: //api.rubyonrails.org/classes/ActionMailer/Base.html
Note: You may have to edit the file again after a Gitlab update
注意:您可能需要在 Gitlab 更新后再次编辑该文件
回答by topher
For Gitlab > 7 omnibus, edit /etc/gitlab/gitlab.rbas below and run sudo gitlab-ctl reconfigure
对于 Gitlab > 7 综合,编辑/etc/gitlab/gitlab.rb如下并运行sudo gitlab-ctl reconfigure
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp password"
gitlab_rails['smtp_domain'] = "example.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
Source: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md
来源:https: //gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md
回答by Jimothy
The email:host:configuration in gitlab.ymlisn't actually for the mail server/SMTP host. It's used to construct the links to your Gitlab host in the email. We call our gitlab server 'gitlab.local' (and have a DNS entry for it), so our configuration says host: gitlab.local.
中的email:host:配置gitlab.yml实际上不是针对邮件服务器/SMTP 主机的。它用于在电子邮件中构建指向 Gitlab 主机的链接。我们称我们的 gitlab 服务器为“gitlab.local”(并且有一个 DNS 条目),所以我们的配置说host: gitlab.local.
This way, when users receive an email from Gitlab, the links will work, instead of linking to http://localhost/, as is the default.
这样,当用户收到来自 Gitlab 的电子邮件时,链接将起作用,而不是http://localhost/默认链接到。
There's some redundant configuration in there. For the git clone URLs to be displayed correctly within Gitlab, you also need to configure web:host:and git_host:host:with the same host name.
那里有一些冗余配置。为了在 Gitlab 中正确显示 git clone URL,您还需要配置web:host:和git_host:host:使用相同的主机名。
web:
host: gitlab.local
port: 80
https: false
email:
host: gitlab.local
protocol: http
git_host:
host: gitlab.local
If you are using HTTPS, change web:https:, web:port:, and email:protocol:.
如果您正在使用HTTPS,变化web:https:,web:port:和email:protocol:。
回答by Girish KG
This is my entries at the end in /config/environment/production.rb and that is working for me.
这是我最后在 /config/environment/production.rb 中的条目,这对我有用。
Comment out sendmail options and use external SMTP relays
注释掉 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 => '[email protected]', ## 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
回答by yourcomputergenius
Apparently the location of these settings has changed (a few times) since this question was originally asked. Currently as of 2018-11-02:
显然,自从最初提出这个问题以来,这些设置的位置已经改变(几次)。目前截至 2018-11-02:
The settings are in gitlab.rbas per the official documentation:
根据gitlab.rb官方文档设置:


