GitLab电子邮件设置:通过另一个邮件服务器发送
默认情况下,gitlab在gitlab.yml中有下一个配置:
email: from: notify@gitlabhq.com host: gitlabhq.com
但是,我需要指定其他变量(主机,端口,用户,密码等)来使用其他邮件服务器。
我是怎么做到的?
这也让我很困惑。 但要更改邮件设置,请在config / environments / production.rb中编辑它们。只需添加一个config.action_mailer.smtp_settings,就像常规rails应用程序一样。
现在它与Gitlab 5.2+完全不同。
它位于“/home/git/gitlab/config/initializers/smtp_settings.rb.sample”中,我们只需按照其中的说明操作即可。
注意 :此方法对旧版本的Gitlab很有用。 有关更新版本, 请参阅 Girish 的答案 。
在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 => 'gitlab@yourserver.com', :password => 'yourPassword', :enable_starttls_auto => true }
有关可能配置的更详细说明,请参阅ActionMailer文档: http : //api.rubyonrails.org/classes/ActionMailer/Base.html
注意 :您可能必须在Gitlab更新后再次编辑该文件
对于Gitlab> 7 omnibus,编辑/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'
资料来源: https : //gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/smtp.md
email:host:
gitlab.yml
配置实际上并不适用于邮件服务器/ SMTP主机。 它用于在电子邮件中构建指向Gitlab主机的链接。 我们称我们的gitlab服务器为’gitlab.local’(并为其提供了一个DNS条目),因此我们的配置为host: gitlab.local
。
这样,当用户从Gitlab收到电子邮件时,链接将起作用,而不是链接到http://localhost/
,这是默认设置。
那里有一些冗余配置。 为了在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
如果您使用的是HTTPS,请更改web:https:
, web:port:
和email:protocol:
.
这是我在/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
显然,这个设置的位置已经改变(几次),因为最初问这个问题。 目前截至2018-11-02:
根据官方文档,设置在gitlab.rb
中: