Gitlab服务器配置gmail企业邮箱,实现自动为用户发送邮件
1 2 3 4 5 | https://www.bilibili.com/read/cv12458883 https://www.cnblogs.com/yoyoketang/p/10272544.html https://www.cnblogs.com/yoyoketang/p/10287345.html https://docs.gitlab.com/omnibus/settings/smtp.html https://blog.csdn.net/qianghaohao/article/details/79331895?utm_source=blogxgwz5 |
本文介绍如何为Gitlab服务配置邮箱,实现服务器向用户自动发送邮件。发邮件的使用场景有很多,比如,用户忘记密码后申请密码重置,用户自行注册账户时,接受邮件用于验
证账户等。
一. 配置前准备工作及说明
1. 服务器系统版本:CentOS 7
2. postfix,并在终端运行systemctl status postfix检查服务是否已在运行状态,如果显示activate则表示正在运行
1 2 3 | rpm -qa | grep postfix //查看下是否已经安装好 systemctl restart postfix.service //重启postfix服务 systemctl status postfix.service //查看是否已经在线 |
2-2. 解决报错问题.
1 2 | 启动过程中如果报错: Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details |
2-3. 解决办法:
1 | vi /etc/postfix/main.cf |
1 2 3 4 | inet_interfaces = localhost //改成 inet_interfaces = all # Enable IPv4, and IPv6 if supported inet_protocols = all //改成 inet_protocols = ipv4 |
2-4. 然后再重启并开机自启动就成功
1 2 3 | systemctl restart postfix.service //重启postfix服务 systemctl status postfix.service //查看是否已经在线 systemctl enable postfix.service //开机自启动 |
3.邮箱信息准备,以gmail邮箱为例
1 | vi /etc/gitlab/gitlab.rb |
3-1. 假设ancky2006@gmail.com
1 2 3 4 5 6 7 8 9 10 11 12 | gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.gmail.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "ancky2006@gmail.com" gitlab_rails['smtp_password'] = "email-id-password" gitlab_rails['smtp_domain'] = "smtp.gmail.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = false gitlab_rails['smtp_pool'] = false ... gitlab_rails['smtp_openssl_verify_mode'] = 'peer' |
3-2. 修改完成并保存后,在终端使配置生效
1 | gitlab-ctl reconfigure |
3-3. 测试邮箱设置是否生效
1 2 | gitlab-rails console Notify.test_email('info@bndstone.com','test Gitlab Email','Test').deliver_now //向测试邮箱info@bndstone.com发送邮件 |
3-4. 运行测试时报错,
1 | Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt) |
原因,gmail后台STMP的服务没有开启.
解决方法:
3-4-1. 进入邮箱后台.
3-4-2. 设置 – 查看所有设置
3-4-3. 转发和POP/IMAP
3-4-4. 启用IMAP
3-4-5. 停用2步验证
1 | https://myaccount.google.com/security?pmr=1 |
否则下一步不会跳出来.
3-4-6. 选择允许
1 | https://myaccount.google.com/lesssecureapps |
3-4-7.
1 | https://accounts.google.com/b/0/displayunlockcaptcha |
3-5. 再测试邮箱设置是否生效
,发现已经成功发送了
1 2 | gitlab-rails console Notify.test_email('info@bndstone.com','test Gitlab Email','Test').deliver_now //向测试邮箱ancky2006@gmail.com发送邮件 |
4. 我想换成google企业邮箱, 我的是info@bndstone.com
1 | vi /etc/gitlab/gitlab.rb |
4-1. 先把邮箱账号密码.修改一下.
1 2 3 4 5 6 7 8 9 10 11 12 | gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.gmail.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "info@bndstone.com" //账号改一下 gitlab_rails['smtp_password'] = "email-id-password" //密码改一下 gitlab_rails['smtp_domain'] = "smtp.gmail.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = false gitlab_rails['smtp_pool'] = false ... gitlab_rails['smtp_openssl_verify_mode'] = 'peer' |
4-2. 修改完成并保存后,在终端使配置生效
1 | gitlab-ctl reconfigure |
4-3. 发送测试邮箱
1 2 | gitlab-rails console Notify.test_email('ancky2006@gmail','test Gitlab Email','Test').deliver_now //向测试邮箱ancky2006@gmail.com发送邮件 |
4-4. 运行测试时报错,
1 2 | Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted. Learn more at) Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt) |
4-5. 邮箱里收到一封警告邮件
4-6. 点 “是的,是本人操作”
4-7. 点继续.
1 | https://accounts.google.com/b/0/displayunlockcaptcha |
4-8. 两步验证
4-8-0. 用户 – info@bndstone.com – 新增两步验证 – 把 两步验证 加上去,点保存
4-8-1. 输入网站 – 两步验证
1 | https://www.google.com/settings/general-light?ref=/ |
4-8-2. 输入账号密码:
4-8-3. 输入手机号 – 下一步
4-8-4. 输入手机收到的验证码 – 下一步
4-8-5. 启用
4-8-6. 看到如下就说明已经成功了
4-9. 申请专用密码,用于gitlab发邮件
4-9-1. Google应用 – 管理
4-9-2. 安全性
4-9-3. 安全性较低的运用
4-9-4. 让用户管理他们能否访问安全性较低的运用
4-10. 申请专用密码:
4-10-1. 输入如下地址:
1 | https://security.google.com/settings/security/apppasswords |
4-10-2. 输入linux – 生成
4-10-3. 把密码复制下来 – 完成
4-11. 修改gmail密码为专用密码:
4-12. 测试是否已经成功
1 2 | gitlab-rails console Notify.test_email('271824820@qq.com','test Gitlab Email','Test').deliver_now |
gmail 私人邮箱,用的是关闭两步验证,用登陆密码设置。感觉不是很安全.
gmail 企业邮箱,用的是启用两步验证,用专用密码设置。感觉安全很多.