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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

176 views 0 4
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