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

 <p>bleh</p> 

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 = "something@something.com"
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);
email.setMimeType("text/html");
email.setSubject(subject);
email.setBody(body);
mailServer.send(email);
} else {
// Problem getting the mail server from JIRA configuration, log this error
}
}

sendEmail (emailAddr, subject, body)

 

1 answer

1 accepted

1 vote

Hello,

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:

"<p>bleh</p>" 

Sending the email with the body formatted as: 

"&lt;p&gt;bleh&lt;/p&gt;" 

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. :)

Jenna

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
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