GitLab 配置邮箱
设置 SMTP 发送邮件
这里以腾讯企业邮箱为例,其他邮箱可以参考 设置 SMTP 发送邮件。
SMTP 和 POP3/IMAP 协议
SMTP 负责发送邮件,POP3/IMAP 负责接收邮件。其中 IMAP 基本上替换掉了 POP3。
用户在使用客户端(例如 Foxmail)时,需要为这个客户端配置 SMTP 和 IMAP 服务器的地址和端口号。写完邮件后,发送到对应邮件服务器上的 SMTP 服务。邮件服务器收到客户编写完的邮件后,根据发件人和收件人的 domain 是否相同(例如都是 xx@qq.com
),分为两种处理方式:
- domain 相同:SMTP 服务将邮件转给本地的 POP3/IMAP 服务。
- domain 不相同:SMTP 服务先通过 DNS 查找,找到收件人对应 domain 的 IP 地址,然后将邮件发送到这台服务器上的 SMTP 服务,后续步骤跟上一步相同。
设置
根据 GitLab 的不同安装方式(docker-compose、docker、二进制或源码安装),设置邮件的方式不同。
一直没找到邮件的日志位置,所以也不知道到底哪里报错。但是可以参考下面部分,通过 Ruby 控制台发邮件,会打印所有的错误信息。
以 root 用户身份登录后,在浏览器中访问 GitLab 时,在 URL 后添加 /api/v4/application/settings
,可以看到所有的设置,每个参数的含义可以 参考这里。
通过 docker-compose 设置(测试成功)
简单便捷,推荐。
修改 docker-compose.yml 文件后,通过 docker-compose up
命令重新加载配置(注意对于腾讯企业邮箱 SMTP_TLS 这个参数必须设置,且必须为 true,此时才会开启 TLS/SSL 加密):
- SMTP_ENABLED=true
- SMTP_DOMAIN=exmail.qq.com
- SMTP_HOST=smtp.exmail.qq.com
- SMTP_PORT=465
- SMTP_USER=yeguan@szhuizhong.cn
- SMTP_PASS=yg123lhf
- SMTP_STARTTLS=true
- SMTP_TLS=true
- SMTP_AUTHENTICATION=login
注意,下面两个参数也要配置。GitLab 发出的确认邮件中的所有连接都会指向这两个参数设置的地址及端口:
- GITLAB_HOST=https://gitlab.mydomain.com
- GITLAB_PORT=10080
上面的设置,会影响容器中的 /home/git/gitlabconfig/initializers/smtp_settings.rb
文件。容器中所有 SMTP 相关设置都从这个文件获取,内容如下:
# To enable smtp email delivery for your GitLab instance do the following:
# 1. Rename this file to smtp_settings.rb
# 2. Edit settings inside this file
# 3. Restart GitLab instance
#
# For full list of options and their values see http://api.rubyonrails.org/classes/ActionMailer/Base.html
#
# If you change this file in a Merge Request, please also create a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requestsif Rails.env.production?Rails.application.config.action_mailer.delivery_method = :smtpActionMailer::Base.delivery_method = :smtpActionMailer::Base.smtp_settings = {address: "smtp.exmail.qq.com",port: 465,user_name: "yeguan@szhuizhong.cn",password: "********",domain: "exmail.qq.com",authentication: "login",enable_starttls_auto: true,openssl_verify_mode: 'none',tls: true}
end
直接修改容器中的配置文件(没测试)
编辑 /home/gitlab/gitlab/config/environments/production.rb
或 /home/git/gitlab/config/environments/production.rb
,把 config.action_mailer.delivery_method = :sendmail
这一行前面加 #
符号注释掉,下面添加:
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = trueconfig.action_mailer.smtp_settings = {:address => "smtp.exmail.qq.com",:port => 465,:domain => 'exmail.qq.com',:user_name => 'yeguan@szhuizhong.cn',:password => 'xxx',:authentication => :plain,:ssl => true,:enable_starttls_auto => true
}
编辑 /etc/gitlab/gitlab.rb
文件进行设置(没测试)
进入容器
docker exec -it gitlab bash
修改配置文件
vi /etc/gitlab/gitlab.rb
内容如下:
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = ""
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
gitlab_rails['smtp_domain'] = ""
重新加载配置并重启
gitlab-ctl reconfigure
gitlab-ctl restart
测试 SMTP 配置是否成功
查看容器的日志
通过容器安装时,如果 gitlab-ctl 和 gitlab-rails 不可用,可以直接进入容器查看日志:
docker exec -it gitlab_1 bash
cd /var/log/gitlab
例如,GitLab 的时区不支持 Shanghai,只支持 Beijing,设置为 Shanghai 会报错无法启动:
TZ=Asia/Shanghai
GITLAB_TIMEZONE=Shanghai
时区报错时,通过 cat gitlab/unicorn.stderr.log
查看日志,会有这么一行:
/home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/core_ext/time/zones.rb:72:in `rescue in find_zone!': Invalid Timezone: Shanghai (ArgumentError)
点击忘记密码
最简单的方法,在登录页面, 点击忘记密码就会自动发送邮件。如果有异常,可以执行下面的命令查看日志:
gitlab-ctl tail
用 Rails 控制台
配置完成后可以用 Rails 控制台验证邮件是否能发送成功。
1. 进入 rails 控制台
在 GitLab 服务器上,执行:
gitlab-rails console
如果是通过 Docker 安装的,可能没有上面的命令,此时可以通过 docker exec -it xx bash
进入容器后使用 bundle
命令:
bundle exec rails console production
2. 检查 ActionMailer 的 delivery_method 参数是否是你设置的值
如果是 SMTP 则会显示 :smtp
。如果是 Sendmail 则会显示 :sendmail
irb(main):001:0> ActionMailer::Base.delivery_method
=> :smtp
3. 检查邮件的设置
irb(main):002:0> ActionMailer::Base.smtp_settings
=> {:address=>"smtp.exmail.qq.com", :port=>465, :user_name=>"yeguan@szhuizhong.cn", :password=>"********", :domain=>"exmail.qq.com", :authentication=>"login", :enable_starttls_auto=>true, :openssl_verify_mode=>"none", :tls=>false}
如果有异常之处,可以检查邮件服务对应的日志(例如 /var/log/mail.log
)。
4. 发送测试邮件
进入控制台后,在控制台提示符后输入下面的命令发送一封测试邮件:
irb(main):003:0> Notify.test_email('kikajack@163.com', 'Hello World', 'This is a test message').deliver_nowNotify#test_email: processed outbound mail in 1.5msSent mail to kikajack@163.com (60238.9ms)
Date: Fri, 18 May 2018 02:28:11 +0000
From: GitLab <yeguan@szhuizhong.cn>
Reply-To: GitLab <yeguan@szhuizhong.cn>
To: kikajack@163.com
Message-ID: <5afe3a3b9f941_2d3b6cd0a48166@f258a250dfea.mail>
Subject: Hello World
Mime-Version: 1.0
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>This is a test message</p></body></html>Net::ReadTimeout: Net::ReadTimeoutfrom /usr/lib/ruby/2.3.0/net/protocol.rb:176:in `rbuf_fill'from /usr/lib/ruby/2.3.0/net/protocol.rb:154:in `readuntil'from /usr/lib/ruby/2.3.0/net/protocol.rb:164:in `readline'from /usr/lib/ruby/2.3.0/net/smtp.rb:955:in `recv_response'from /usr/lib/ruby/2.3.0/net/smtp.rb:556:in `block in do_start'from /usr/lib/ruby/2.3.0/net/smtp.rb:965:in `critical'from /usr/lib/ruby/2.3.0/net/smtp.rb:556:in `do_start'from /usr/lib/ruby/2.3.0/net/smtp.rb:521:in `start'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/mail-2.7.0/lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:2160:in `do_delivery'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in `block in deliver'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:543:in `block in deliver_mail'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in `block in instrument'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications/instrumenter.rb:20:in `instrument'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/notifications.rb:164:in `instrument'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/base.rb:541:in `deliver_mail'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/mail-2.7.0/lib/mail/message.rb:260:in `deliver'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/actionmailer-4.2.10/lib/action_mailer/message_delivery.rb:85:in `deliver_now'from (irb):4from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:110:in `start'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.10/lib/rails/commands/console.rb:9:in `start'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:68:in `console'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39:in `run_command!'from /home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/railties-4.2.10/lib/rails/commands.rb:17:in `<top (required)>'from bin/rails:14:in `require'from bin/rails:14:in `<main>'
上面发送失败,同时报了一堆错误。Ruby 我不懂,所以去查资料。mail SSL smtp 发送不成功 (QQ/163) 这里讲的很明白,TLS/SSL 必须设置为 true。
修改设置后,再次发送邮件,成功:
irb(main):003:0> Notify.test_email('kikajack@163.com', 'Hello World', 'This is a test message').deliver_nowNotify#test_email: processed outbound mail in 313.8msSent mail to kikajack@163.com (1993.6ms)
Date: Fri, 18 May 2018 06:59:37 +0000
From: GitLab <yeguan@szhuizhong.cn>
Reply-To: GitLab <yeguan@szhuizhong.cn>
To: kikajack@163.com
Message-ID: <5afe79d9e5b57_2e96b90b8507d6@f9147604e002.mail>
Subject: Hello World
Mime-Version: 1.0
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>This is a test message</p></body></html>=> #<Mail::Message:185028380, Multipart: false, Headers: <Date: Fri, 18 May 2018 06:59:37 +0000>, <From: GitLab <yeguan@szhuizhong.cn>>, <Reply-To: GitLab <yeguan@szhuizhong.cn>>, <To: kikajack@163.com>, <Message-ID: <5afe79d9e5b57_2e96b90b8507d6@f9147604e002.mail>>, <Subject: Hello World>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
各邮箱的区别
primary email
用户注册时的邮箱,默认状况下,通知邮箱也是同一个。可以在个人信息中修改。
notification email
用来接收系统邮件,如果 test、merge、review 通知等,和 primary email 一致就行。
public email
用户展示出来的个人信息,GitLab 并不使用。
ssh key 邮箱
设置公钥的时候是用的这个邮箱。用户将公钥添加到 GitLab 之后,可以在这个公钥的主机上 push 和 pull 代码。用户的commit后,系统鉴别的头像和用户名都和ssh key中的邮箱没有关系。
$ ssh-keygen -t rsa -b 4096 -C "565066158@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ZZYs4/OKNCJLoMCJ5/4vf+Uvq0RvcD64YSw0VS6mBQE 565066158@qq.com
The key's randomart image is:
+---[RSA 4096]----+
| E.o. . |
| . + . |
| B B |
|o . * B |
|+o. + S . |
|o+ . + O. |
|. + . + *o* |
| o o.o *.=o. |
| o..++.+..+. |
+----[SHA256]-----+
git 配置邮箱
用户需要在 Git 软件中设置邮箱和用户名:
$ git config user.name 'jack'
$ git config user.email '123@qq.com'
可以在 ~/.gitconfig
文件中实现全局配置。
用户提交代码之后,GitLab 会将 git config 中的邮箱与用户 email 进行匹配。如果匹配成功,则可以上传。
值得注意的是:当邮箱匹配时,commit 的用户名是用户的 GitLab 的用户名,而不是 git config 中的。如果邮箱不匹配,则使用 git config 中的用户名和邮箱。
转载于:https://www.cnblogs.com/kika/p/10851615.html
GitLab 配置邮箱相关推荐
- gitlab 配置邮箱服务
1,配置邮件服务的用途 合并请求邮件通知 账号注册邮件通知 修改密码邮件通知 2,配置步骤 开启qq邮箱smtp服务 修改gitlab配置文件 测试邮件服务 3,修改gitlab.rb 配置文件 vi ...
- gitlab 配置QQ邮箱
gitlab 配置QQ邮箱 gitlab版本 官方文档 邮箱厂商 需要修改的配置文件 修改的配置内容 调试控制台 正确测试结果 [root@xxxxxxxxxxxxxx gitlab]# gitlab ...
- gitlab配置邮件服务(QQ邮箱)图解教程
一.配置邮箱服务的用途 当有合并请求时,账号注册,修改密码时,可通过邮件通知 ,邮件验证 ,邮件修改实现 二.配置步骤 1.开启QQ邮箱的SMTP服务 设置-->账户-->smtp-- ...
- RHEL7/CentOS7在线和离线安装GitLab配置使用实践
前言 GitLab Community Edition 新版本已经集成了CI/CD的支持,从某种程度上来说可以告别对于Jenkins的依赖,我本来计划是写基于Docker部署GitLab但感觉还是有点 ...
- Jenkins集成Gitlab配置提交流水线
在大型项目开发过程中,开发人员频繁提交新代码,然后在项目生命周期结束时将其集成到代码仓库.在集成的时候往往会需要消耗大量的时间去解决构建编译等问题.如何配置 Jenkins 与版本控制系统 Gitla ...
- gitlab设置邮箱服务器
背景 gitlab用户注册,批量创建用户,管理员创建用户默认都需要用邮箱确认,gitlab安装完毕之后默认是邮箱不生效的,这也很合情合理,毕竟如果发通知邮件你需要去设置用哪个邮箱给用户发,所以,发邮件 ...
- gitlab配置域名访问
安装Gitlab完成后: Gitlab默认Nginx80端口 如果机器未占有80端口,可以直接替换成域名,解析后就可以直接访问. grep "^external_url" /etc ...
- 网站发送邮件的邮箱服务器,教各位站长配置邮箱让网站能够发送Email邮件
本文教各位小白站长如何配置邮箱 海外免备案服务器强烈建议 使用163邮箱.使用994端口! QQ邮箱用587端口 (因为很多服务商关闭了25.465端口) 另外163 邮箱也改规则了,以前的不能用现在 ...
- Jenkins 配置邮箱 530Authentication required ,535 uthentication failed 的解决方法
Jenkins 配置邮箱 530Authentication required ,535 uthentication failed 的解决方法 参考文章: (1)Jenkins 配置邮箱 530Aut ...
最新文章
- 【机器视觉案例】(13) 脸部和摄像机间的距离测量,自适应文本大小,附python完整代码
- 15.基于Hadoop的数据仓库Hive第3部分(Hive编程实践)
- [Leetcode]-containsNearbyDuplicate
- linux启动nifi指令,Nifi 组件脚本开发 - ExecuteScript 使用指南 (二)
- 《 第一本Docker书 》读书笔记 --- Docker 各项操作命令及参数说明(docker run 命令各个参数说明)
- Docker Redis部署_04
- java爬虫 京东_java爬虫webmagic 案例爬取动态(ajax+js) 网站京东售价格
- 使用Firebase、Angular 8和ASP.NET Core 3.1保护网站
- 如何快速掌握计算机知识,怎样快速学会电脑 学电脑的5种方法推荐
- 基于大数据的个性化推荐系统
- .NET中代理服务器WebProxy的各种用法
- Android TCP客户端调试助手
- 内部收益率计算公式用计算机,用excel怎么计算内部收益率?
- MediaRecorder录制音频文件
- 目标检测tricks(基于detectron2)
- Finger.01 - ESP8266模块STA模式调试
- 0基础学前端开发,CSS盒子模型居中方法
- easyUI右侧搜索面板下拉列表框样例
- usc计算机科学硕士分支方向,一次说清北美计算机科学硕士的项目,选校,申请,排名,难度...
- keil如何添加STM32系列
热门文章
- Tutorial——使用Maven开发Cloud Driver
- Linux11-RPM软件包和YUM源
- 区块链基础--工作量证明
- mac gource_如何使用Gource显示项目的时间表
- 面试:你了解中兴吗_HTTP简介:您需要了解的所有内容
- react中使用scss_我如何将CSS模块和SCSS集成到我的React应用程序中
- gis中的擦除_擦除—帮助 | ArcGIS for Desktop
- 详解数组中的reduce方法
- 怎样操作vue.js使用3DES加密
- 华为云微服务引擎CSE大量新特性上线,诚邀您免费体验