How to display HTML page inside mail body with email-ext plugin in Jenkins?

For this we need to install the Junit plugin for Jenkins. As if we check the source template of the email-ext plugin as mentioned here, then we can find that for Junit report part, it’s fetching the values from Junit result.

Then we need to call this in the pipeline as mentioned below, assuming we are using SCM for build and we are maintaining a separate JenkinsFile for that.

This will display the email body as mentioned below: –

Now we can easily override this default template. But for that we need to create a folder under jenkinsHome with name “email-templates” and there we need to place the desired template. And the same template file needs to mention in the Pipeline under ‘body’ section. For this please check the official plugin site where it’s mentioned clearly. Sample pipeline code for the same is mentioned below: –

stage ('Send Email') {

        echo "Mail Stage";
     
     

if ("${params.EmailSent}"== 'Yes') {
       

emailext attachLog: true,  attachmentsPattern: 'sample.pdf , sample.xlsx',
body: '''${SCRIPT,template="groovy-html.template"}''',
compressLog: true, subject:  '[${BUILD_STATUS}]${JOB_NAME}', mimeType: 'text/html',
 to: "xxx@gmail.com"
}}