You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slms/docs/EMAIL_CHECKLIST.md

5.7 KiB

Jenkins 邮件通知检查清单

问题:邮件没有触发

检查清单

1. 检查 Jenkins 邮件配置

访问:http://localhost:8084/configure

Extended E-mail Notification 配置:

  • SMTP server 已配置smtp.qq.com
  • SMTP port 已配置465
  • Use SMTP Authentication 已勾选
  • User Name 已填写(完整邮箱地址)
  • Password 已填写(授权码,不是邮箱密码)
  • Use SSL 已勾选
  • Default Recipients 已填写或 Jenkinsfile 中指定了收件人

测试配置:

  • 点击 "Test configuration by sending test e-mail"
  • 输入测试邮箱ldl@chzu.edu.cn
  • 点击 "Test configuration"
  • 检查是否收到测试邮件

2. 检查 Jenkinsfile 配置

  • to: 'ldl@chzu.edu.cn' 已正确配置
  • emailextpost 部分
  • post { success { ... } } 配置正确

3. 检查构建状态

邮件只在以下情况发送:

  • success - 构建成功
  • failure - 构建失败
  • unstable - 构建不稳定(测试失败但继续)

查看构建状态:

访问http://localhost:8084/job/slms/lastBuild/
查看构建结果SUCCESS/FAILURE/UNSTABLE

4. 检查 Jenkins 日志

访问:http://localhost:8084/job/slms/lastBuild/console

搜索关键词:

发送成功通知邮件
准备发送邮件到
成功通知邮件已发送
邮件发送失败

如果看到错误:

javax.mail.AuthenticationFailedException

→ 检查 SMTP 用户名和密码(授权码)

javax.mail.MessagingException: Could not connect to SMTP host

→ 检查 SMTP 服务器地址和端口

com.sun.mail.smtp.SMTPSendFailedException: 550 Invalid User

→ 检查收件人邮箱地址是否正确

5. 检查邮箱设置

QQ 邮箱:

  • 已开启 SMTP 服务
  • 已生成授权码
  • 授权码正确填写到 Jenkins

163 邮箱:

  • 已开启 IMAP/SMTP 服务
  • 已设置客户端授权密码

企业邮箱:

  • 联系管理员确认 SMTP 配置
  • 确认是否需要白名单

6. 检查防火墙和网络

  • Jenkins 服务器可以访问 SMTP 服务器
  • SMTP 端口465/587未被防火墙阻止

测试连接:

# Windows
telnet smtp.qq.com 465

# 或使用 PowerShell
Test-NetConnection -ComputerName smtp.qq.com -Port 465

7. 检查邮件插件

访问:http://localhost:8084/pluginManager/installed

必需插件:

  • Email Extension Plugin (已安装且已启用)
  • Mailer Plugin (已安装且已启用)

8. 手动触发测试

方法 1在 Jenkins Script Console 测试 访问:http://localhost:8084/script

import javax.mail.*
import javax.mail.internet.*

def props = new Properties()
props.put("mail.smtp.host", "smtp.qq.com")
props.put("mail.smtp.port", "465")
props.put("mail.smtp.auth", "true")
props.put("mail.smtp.ssl.enable", "true")

def session = Session.getInstance(props, new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("your-email@qq.com", "your-auth-code")
    }
})

def message = new MimeMessage(session)
message.setFrom(new InternetAddress("your-email@qq.com"))
message.addRecipient(Message.RecipientType.TO, new InternetAddress("ldl@chzu.edu.cn"))
message.setSubject("Jenkins 邮件测试")
message.setText("这是一封测试邮件")

Transport.send(message)
println "邮件发送成功!"

方法 2触发一次构建

# 推送代码触发构建
git commit --allow-empty -m "test: 触发邮件测试"
git push

常见问题解决

问题 1: 收不到邮件但日志显示发送成功

可能原因:

  • 邮件进入垃圾箱
  • 邮箱服务器延迟

解决方案:

  1. 检查垃圾邮件文件夹
  2. 将 Jenkins 邮箱加入白名单
  3. 等待几分钟再检查

问题 2: 授权码认证失败

可能原因:

  • 授权码输入错误
  • 授权码已过期
  • 未开启 SMTP 服务

解决方案:

  1. 重新生成授权码
  2. 确认 SMTP 服务已开启
  3. 复制粘贴授权码,避免手动输入错误

问题 3: 连接超时

可能原因:

  • 防火墙阻止
  • SMTP 端口错误
  • 网络问题

解决方案:

  1. 检查防火墙设置
  2. 确认端口QQ/163 使用 465SSL或 587TLS
  3. 测试网络连接

问题 4: 邮件内容乱码

可能原因:

  • 字符集配置错误

解决方案: 在 Jenkins 配置中设置:

  • Default Content Type: text/html; charset=UTF-8
  • Charset: UTF-8

验证邮件功能

成功标志

  • Jenkins 日志显示:✓ 成功通知邮件已发送到: ldl@chzu.edu.cn
  • 收件箱收到邮件
  • 邮件内容完整,链接可点击
  • 邮件格式正确HTML

邮件内容应包含

  • 构建编号
  • 构建时间
  • Git 提交信息
  • 构建结果列表
  • Jenkins 制品下载链接
  • 头歌 Release 分支链接
  • SonarQube 报告链接

当前配置

收件人: ldl@chzu.edu.cn

邮件类型:

  1. 成功邮件 - 构建成功时发送
  2. 失败邮件 - 构建失败时发送
  3. ⚠️ 不稳定邮件 - 测试失败但继续时发送

触发条件:

  • 每次构建完成后自动发送
  • 根据构建结果选择邮件类型

下一步

如果以上都检查完毕仍然收不到邮件:

  1. 查看 Jenkins 系统日志

    • 访问:http://localhost:8084/log/all
    • 搜索:mailemail
  2. 启用调试日志

    • 访问:http://localhost:8084/log/
    • 添加新的 Loggerhudson.plugins.emailext
    • 级别:ALL
  3. 联系邮箱服务提供商

    • 确认 SMTP 服务状态
    • 检查是否有发送限制
  4. 尝试其他邮箱

    • 使用 Gmail 或 163 邮箱测试
    • 排除特定邮箱的问题