Hi everyone,
I have created script listener with ScriptRunner that iterates through all subtasks and their linked issues, and then the email is send out with the results.
Everything works great but I would like to know how to create a hyperlink in email body, since
sendEmail("test@company.com", "Testing", emailBody)
is giving only string back. The reason I want to do this is that the link is really long, and it doesn't look nice. So is there a way to enter HTML tag to the email body? or any other way to insert hyperlink.
Here is the code I'm using:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.link.IssueLink;
import java.text.SimpleDateFormat;
import com.atlassian.jira.mail.Email
import com.atlassian.mail.server.SMTPMailServer
IssueManager issueManager = ComponentAccessor.getIssueManager();
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issue = event.getIssue()
String emailBody
def activityField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_13001");
def findingsLinkField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_18601");
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
// Gets all subtasks of the projects.
final Collection < Issue > subTaskObjects = issue.getSubTaskObjects();
if(subTaskObjects != null && subTaskObjects.size() != 0)
{
for (Issue subTaskObject : subTaskObjects)
{
if(subTaskObject.issueType.name == "Test Review")
{
if(subTaskObject != null)
{
// Gets all linked issues of the subtasks
final List <IssueLink> issuelinks = issueLinkManager.getInwardLinks(subTaskObject.getId());
if(issuelinks != null && issuelinks.size() != 0)
{
for (IssueLink issueLink : issuelinks)
{
def mutablelink = issueManager.getIssueObject(issueLink.getSourceId())
if (issueLink.getIssueLinkType().name == "Test finding" && issueLink != null && mutablelink.status.name == "open")
{
def activity = mutablelink.getCustomFieldValue(activityField);
def findingsLink = mutablelink.getCustomFieldValue(findingsLinkField);
// I would like to add this link to hyper link
def url = "mailto:test@company.com?subject=Test%20Project%20Finding:%20Comment%20from%20Responsible%20("+ mutablelink.key +")&body=Please%20send%20a%20short%20status%20update%20for%20this%20Test%20Review%20Finding%20to%20the%20already%20entered%20recipient.%20A%20comment%20to%20the%20Finding%20will%20be%20added%20automatically%20in%20Q-Tool%20where%20the%20responsible%20QE-CS%20will%20react%20accordingly.%0D%0A"
URL obj = new URL(url)
emailBody = emailBody + "Finding: ${mutablelink.key}<br> activityField: ${activity} \n " + "Url: ${obj} "
}
}
}
}
}
}
}
def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer)
{
Email email = new Email(emailAddr)
email.setSubject(subject)
email.setBody(body)
mailServer.send(email)
log.debug("Mail sent")
} else {
log.warn("Please make sure that a valid mailServer is configured")
}
}
sendEmail("test@company.com", "Testing", emailBody)
use
email.setMimeType("text/html")
and then add the html hyperlink in the body.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.