Skip to main content
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.
A screenshot of the Jenkins web UI open to the Pipeline Syntax Snippet Generator, showing the "emailext: Extended Email" 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.
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:
Common default variables supported by the plugin (usable in pipeline arguments and in the Extended E-mail configuration) include: 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):
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.
A Gmail web inbox screenshot showing a "jenkins" 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.
Example relevant console output (trimmed):
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:
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):
A screenshot of the Jenkins "Manage Jenkins > System" email settings showing SMTP Port set to 465, a selected masked credentials entry, and the "Use SSL" option checked with advanced email properties visible.
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.
Quick SMTP & HTML checklist: References and further reading: 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.

Watch Video

Practice Lab