Example code for sending emails through Jenkins

v2.61 you can just do
in the Default Content session and keep the format
Solution 2:
You should be able to combine Environment Script plugin with Email-ext plugin to achieve the desired functionality.
Check the generate environment variable from script option in the build environment section.
Solution:
you need to use jekins zip utility to create zip file for the folder and then use the emailext plugin to send email with attachment see below example:
Solution 1:
With the Email Extension Plugin


Solution:

To send an email with an attachment, you can use the emailext plugin and create a zip file for the folder using Jenkins’ zip utility. Refer to the example below for guidance.

 pipeline {
    agent any
    stages {
        stage('Testing') {
            steps{
               bat "del test.zip"
               zip zipFile: 'test.zip', archive: false, dir: 'directory pattern as per your structure'
            }
        }
    }
    post {
        failure {
            emailext attachmentsPattern: 'test.zip', body: '''${SCRIPT, template="groovy-html.template"}''', 
                    subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Failed", 
                    mimeType: 'text/html',to: "email id"
            }
         success {
               emailext attachmentsPattern: 'test.zip', body: '''${SCRIPT, template="groovy-html.template"}''', 
                    subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful", 
                    mimeType: 'text/html',to: "email id"
          }      
    }
}

Frequently Asked Questions