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 = "<p>bleh</p>"
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)
Hello,
I don't believe you need to use "<p>" 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:
"<p>bleh</p>"
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
thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.