Custom script to send email as HTML? (Not built in send custom email)

Hi, sorry if I've missed something obvious. But basically I want to use a custom script instead of the built in custom email for more flexibility. I have used basics I've found in other posts and plan to build this up for various post functions.

My problem though is that I'm not sure how to actually get the email to send as html? I set mimetype to text/html but the email body i receive reads like


Here is the script which I'm testing in script console (also if you feel like pointing out better ways of setting up the sendEmail please do so)

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

subject = "test"
emailAddr = ""
body = "&lt;p&gt;bleh&lt;/p&gt;"

def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentManager.getInstance().getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(emailAddr);
} else {
// Problem getting the mail server from JIRA configuration, log this error

sendEmail (emailAddr, subject, body)


1 answer

1 accepted

2 votes
Accepted answer


I don't believe you need to use "&lt;p&gt;" and such in order to write your HTML. I was able to send an email correctly formatted as HTML using just the expected HTML code inside of the body like this:


Sending the email with the body formatted as: 


caused me to recieved "<p>bleh</p>" as you had. 

Hopefully this helps you out! Let me know if this doesn't fix the problem or if you have any other questions. :)


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

457 views 8 27
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you