Search code examples
emailjenkinspluginssmtpamazon-ses

How to set from address in Jenkins with email-ext plugin?


Using AWS SES as mail server. Set smtp, username and password at Extended E-mail Notification area. But didn't find where to set from address. If don't set it, the send mail will be failure:

SendFailedException message: 501 Invalid MAIL FROM address provided

At Jenkins Location area, there is a System Admin e-mail address input. Even set an address there, can't send mail successfully.

enter image description here


Solution

  • We use Jenkins pipeline and we set the from via the emailext option:

    def subject = "JENKINS-NOTIFICATION: ${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" 
    
    emailext(
                mimeType: 'text/html',
                replyTo: '$DEFAULT_REPLYTO',
                subject: subject,
                from: 'jenkins@host.com',
                to: 'dummy@corp.com',
                body: '${SCRIPT,template="email.template"}',
                attachLog: true,
                compressLog: true,
                recipientProviders: [[$class: 'DevelopersRecipientProvider']]
        )
    

    See also the documentation on which options you can define.