> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Email Extension Notification Pipeline

> Guide to sending Jenkins pipeline build notifications using the Email Extension plugin, including snippet generation, attaching logs and files, and sending HTML formatted emails

This guide demonstrates how to send build notifications from a Jenkins Declarative pipeline using the Email Extension plugin (Extended E-mail). You'll learn how to generate the `emailext` snippet, add an email step to a Declarative pipeline `post` action, attach build logs and files, and send HTML-formatted notifications.

Create a new Jenkins pipeline job (for example, "Pipeline Email Notification") and open the Pipeline Syntax / Snippet Generator to produce the `emailext` step.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-pipeline-snippet-generator-emailext.jpg?fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=69676d2a2be0c89ec2b3c0fc1862d777" alt="A screenshot of the Jenkins web UI open to the Pipeline Syntax Snippet Generator, showing the &#x22;emailext: Extended Email&#x22; sample step with fields for To, Recipient Providers, Subject, and Body. The left sidebar lists links like Snippet Generator, Declarative Directive Generator, and documentation references." width="1920" height="1080" data-path="images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-pipeline-snippet-generator-emailext.jpg" />
</Frame>

Use the snippet generator to choose the "emailext" step (from the Extended E-mail plugin). Populate fields such as To, Recipient Providers, Subject, Body and Advanced options (for example, Attach Logs). The generator outputs a Groovy snippet you can paste into your pipeline. A minimal generated snippet looks like:

```groovy theme={null}
emailext body: '', recipientProviders: [developers()], subject: ''
```

Common default variables supported by the plugin (usable in pipeline arguments and in the Extended E-mail configuration) include:

| Variable | Meaning |
| - | - |
| `$DEFAULT_RECIPIENTS` | Default recipient list configured globally |
| `$DEFAULT_SUBJECT` | Default subject set in Extended E-mail Notification |
| `$DEFAULT_CONTENT` | Default message body (can be HTML) |

Below is a minimal Declarative pipeline example. It creates a file during a stage and then sends an email in the `post` section. Note `emailext` is invoked as a step with named arguments (`attachLog`, `body`, `subject`, `to`, `attachmentsPattern`):

```groovy theme={null}
pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                sh "echo 'Testing pipeline-email-notification' > testFile.txt"
            }
        }
    }

    post {
        always {
            emailext attachLog: true,
                     body: '$DEFAULT_CONTENT',
                     subject: '$DEFAULT_SUBJECT',
                     to: '$DEFAULT_RECIPIENTS',
                     attachmentsPattern: 'testFile.*'
        }
    }
}
```

How it works:

* The `Hello` stage generates `testFile.txt`.
* The `post` block runs after the build and calls `emailext`.
* `attachLog: true` attaches the console log.
* `attachmentsPattern` attaches any files matching the glob (here, `testFile.txt`).

When the job finishes, Jenkins will send an email with the console log and the generated `testFile.txt` attached. Example: Jenkins notifications appearing in a Gmail inbox.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/gmail-jenkins-build-notifications-inbox.jpg?fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=fd8a32f84c6817dbe09ca218dd3475c7" alt="A Gmail web inbox screenshot showing a &#x22;jenkins&#x22; label with a list of automated Jenkins build notification emails (subjects like build successes and failures). The message list includes attachments and timestamps along the right." width="1920" height="1080" data-path="images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/gmail-jenkins-build-notifications-inbox.jpg" />
</Frame>

Example relevant console output (trimmed):

```text theme={null}
Started by user siddharth
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/pipeline-email-notification
[Pipeline] stage
[Pipeline] { (Hello)
[Pipeline] sh
+ echo Testing pipeline-email-notification
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] emailext
Sending email to: sid.live.demos@gmail.com
```

Send HTML-formatted notifications

* By default the plugin sends plain text.
* To use HTML, provide an HTML template as the default content (or pass it directly as the `body`) and configure the default content type to `text/html`.

Example HTML template you might paste into the Extended E-mail Notification `Default Content`:

```html theme={null}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Jenkins Build Status</title>
</head>
<body>
  <h1 style="color: #007bff;">Jenkins Build Status Notification</h1>
  <p>Hi team,</p>
  <p>The latest Jenkins build status of job <b>${JOB_NAME}</b> is as follows:</p>

  <table border="1" cellpadding="10">
    <thead>
      <tr>
        <th>Build Number</th>
        <th>Status</th>
        <th>Details</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>${BUILD_NUMBER}</td>
        <td>${BUILD_STATUS}</td>
        <td>Check the <a href="${BUILD_URL}">Build Log</a></td>
      </tr>
    </tbody>
  </table>

  <p>Thanks,</p>
  <p>Your Jenkins Bot</p>
</body>
</html>
```

Before sending HTML, verify these settings (Manage Jenkins > Extended E-mail Notification and System Configuration):

* Set `Default Content` to your HTML template.
* Set `Default Content Type` to `text/html`.
* Confirm SMTP settings (server, port, credentials, SSL/TLS) so Jenkins can successfully deliver mail.

A sample screenshot showing SMTP settings (port, masked credentials, SSL enabled):

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=a0dd552ab21f08eede1bbce557f23811" alt="A screenshot of the Jenkins &#x22;Manage Jenkins > System&#x22; email settings showing SMTP Port set to 465, a selected masked credentials entry, and the &#x22;Use SSL&#x22; option checked with advanced email properties visible." data-og-width="1920" width="1920" data-og-height="1080" height="1080" data-path="images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=280&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=2c739ec5ed971a411b5fa68a9b30aade 280w, https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=560&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=9f764ceca82076f790c3d9e8ed9f2e9e 560w, https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=840&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=5f96e370e73c5b011a0e00ac2dbe996f 840w, https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=1100&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=13127a92c8c9c5ffdd6c2ea1770ca410 1100w, https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=1650&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=0fcf2b044dd6e36547cb7206f16ebaf6 1650w, https://mintcdn.com/kodekloud-c4ac6d9a/eoiWanmIVF-indgd/images/Certified-Jenkins-Engineer/Automation-and-Security/Demo-Email-Extension-Notification-Pipeline/jenkins-email-smtp465-ssl-masked-creds.jpg?w=2500&fit=max&auto=format&n=eoiWanmIVF-indgd&q=85&s=b93f9027b423b5548d3e2c59a5f425b5 2500w" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  When you paste the HTML into the Extended E-mail Notification `Default Content` field, also set `Default Content Type` to `text/html`. If left as plain text, HTML will appear as literal markup in the email.
</Callout>

Quick SMTP & HTML checklist:

| Item | Why it matters |
| - | - |
| SMTP server & port | Required for delivery (e.g., port `465` for SMTPS) |
| Credentials | Credentials must be configured and selected (use masked credentials) |
| SSL/TLS | Enable if your SMTP provider requires it |
| `Default Content Type` | Must be `text/html` to render HTML templates |
| Test job | Run a job that triggers `emailext` to verify attachments and rendering |

References and further reading:

* Email Extension plugin (Extended E-mail): [https://plugins.jenkins.io/email-ext/](https://plugins.jenkins.io/email-ext/)
* Pipeline Syntax / Snippet Generator: [https://www.jenkins.io/doc/book/pipeline/syntax/](https://www.jenkins.io/doc/book/pipeline/syntax/)
* Managing Jenkins — Mail configuration: [https://www.jenkins.io/doc/book/managing/](https://www.jenkins.io/doc/book/managing/)

That covers using the Email Extension plugin in a Declarative Jenkins pipeline: generating the `emailext` snippet, invoking `emailext` from `post` actions, attaching logs/files, and sending HTML-formatted notifications.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-jenkins-engineer/module/4d6d1f39-307c-4fdb-8d2b-834c1650e792/lesson/7cbefa02-9152-4145-9e36-705b8b170459" />

  <Card title="Practice Lab" icon="flask-conical" cta="Learn more" href="https://learn.kodekloud.com/user/courses/certified-jenkins-engineer/module/4d6d1f39-307c-4fdb-8d2b-834c1650e792/lesson/4860d04d-a61e-4d6c-884c-fc7f87a75e63" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.