HTML email with plain mailer plugin on Jenkins

We build our Jenkins from a docker container, setting up that with code requires setting up the plugin from groovy. I didn't want to figure out how to translate our config for the plain mailer plugin to the email-ext plugin. I started using the plain mailer plugin but decided I'd like to send the email in HTML format. Once again, Jenkins docs were terrible, but reading the code, it looked like mimetype was supported.

I came up with the following code to send an HTML email from the Jenkinsfile

  mail to: env.REQUESTOR,
    subject: "Pipeline: ${currentBuild.fullDisplayName} ${currentBuild.result}",
    mimeType: "text/html",
    body: """
<html>
<body>
<h1>Pipeline: ${currentBuild.fullDisplayName}</h1>
<h2><a href="${env.RUN_DISPLAY_URL}">Build ${currentBuild.id} Results</a></h2>
<h2><a href="${env.JOB_DISPLAY_URL}">${currentBuild.projectName}</a></h2>
</body>
</html>
"""

This results in an email that is correctly displayed by Outlook and Gmail.

Just in case someone wants to see the config for the plain mailer...

import hudson.tasks.Mailer
 
def m = Mailer.descriptor()
 
m.setSmtpHost("smtp.example.com")
m.setReplyToAddress("jenkins@example.com")
m.save()

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

https://t.co/AGeihMALAv configuring grub2 with EFI Fri Sep 13 05:20:01 +0000 2019

I published a Thing on @thingiverse! https://t.co/IYpRyEb7Hz #thingalert Tue Jul 23 19:27:57 +0000 2019

Nokogiri install on MacOSX https://t.co/v3An0miW9L Fri Jul 12 15:06:49 +0000 2019

HTML email with plain mailer plugin on Jenkins https://t.co/Z6FSDMDjy8 Thu Jul 11 21:07:25 +0000 2019

git sparse checkout within Jenkinsfile https://t.co/tcL7V8mzFK Thu Jul 11 20:40:53 +0000 2019