Skip to content

1. Install Email Extension Plugin

"Email Extension Plugin" is installed in Jenkins.

  1. Go to Manage Jenkins > Manage Plugins.
  2. Under the Available tab, search for Email Extension Plugin and install it.

2. Configure Email Extension Plugin

After installing the plugin:

  1. Go to Manage Jenkins > Configure System.
  2. In the Extended E-mail Notification section, configure the SMTP server settings (such as the server, port, authentication, and so on).

3. Create a Custom HTML Email Template

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jenkins Build Notification</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; padding: 20px;">
    <table style="width: 100%; max-width: 600px; background-color: #ffffff; margin: auto; border-collapse: collapse; box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);">
        <tr>
            <td style="background-color: #949b94; color: white; padding: 10px; text-align: center;">
                <h1>Jenkins ${PROJECT_NAME}项目构建结果</h1>
            </td>
        </tr>
        <tr>
            <td style="padding: 20px;">
                <p>尊敬的用户:</p>
                <p>${PROJECT_NAME}项目构建结果为 <strong style="color: rgb(241, 47, 33);">Successful</strong>,以下是详细信息:</p>
                <h2>构建信息</h2>
                <ul>
                    <li><strong>项目名称:</strong>${PROJECT_NAME}</li>
                    <li><strong>构建编号:</strong>${BUILD_NUMBER}</li>
                    <li><strong>触发原因:</strong>${CAUSE}</li>
                    <li><strong>构建状态:</strong>${BUILD_STATUS}</li>
                    <li><strong>构建日志:</strong><a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
                    <li><strong>构建URL:</strong><a href="${BUILD_URL}">${BUILD_URL}</a></li>
                    <li><strong>工作目录:</strong><a href="${BUILD_URL}ws">${BUILD_URL}ws</a></li>
                    <li><strong>项目URL:</strong><a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
                </ul>
                
                <h2>最近提交</h2>
                <ul>
                    <li>${CHANGES_SINCE_LAST_SUCCESS}</li>
                </ul>
                <p><a href="${BUILD_URL}changes">提交详情</a></p>
                <p>如有疑问或需要帮助,请随时联系我们。</p>
            </td>
        </tr>
        <tr>
            <td style="background-color: #f4f4f4; text-align: center; padding: 10px;">
                <p>此为系统自动发送的邮件,请勿回复。</p>
            </td>
        </tr>
    </table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Jenkins Build Notification</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; padding: 20px;">
    <table style="width: 100%; max-width: 600px; background-color: #ffffff; margin: auto; border-collapse: collapse; box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);">
        <tr>
            <td style="background-color: #949b94; color: white; padding: 10px; text-align: center;">
                <h1>Jenkins ${PROJECT_NAME}项目构建结果</h1>
            </td>
        </tr>
        <tr>
            <td style="padding: 20px;">
                <p>尊敬的用户:</p>
                <p>${PROJECT_NAME}项目构建结果为 <strong style="color: rgb(241, 47, 33);">Successful</strong>,以下是详细信息:</p>
                <h2>构建信息</h2>
                <ul>
                    <li><strong>项目名称:</strong>${PROJECT_NAME}</li>
                    <li><strong>构建编号:</strong>${BUILD_NUMBER}</li>
                    <li><strong>触发原因:</strong>${CAUSE}</li>
                    <li><strong>构建状态:</strong>${BUILD_STATUS}</li>
                    <li><strong>构建日志:</strong><a href="${BUILD_URL}console">${BUILD_URL}console</a></li>
                    <li><strong>构建URL:</strong><a href="${BUILD_URL}">${BUILD_URL}</a></li>
                    <li><strong>工作目录:</strong><a href="${BUILD_URL}ws">${BUILD_URL}ws</a></li>
                    <li><strong>项目URL:</strong><a href="${PROJECT_URL}">${PROJECT_URL}</a></li>
                </ul>
                
                <h2>最近提交</h2>
                <ul>
                    <li>${CHANGES_SINCE_LAST_SUCCESS}</li>
                </ul>
                <p><a href="${BUILD_URL}changes">提交详情</a></p>
                <p>如有疑问或需要帮助,请随时联系我们。</p>
            </td>
        </tr>
        <tr>
            <td style="background-color: #f4f4f4; text-align: center; padding: 10px;">
                <p>此为系统自动发送的邮件,请勿回复。</p>
            </td>
        </tr>
    </table>
</body>
</html>