I’m working on customizing JIRA notification system to send emails to additional recipients when specific issue events occur. I’ve set up an event listener that captures issue events successfully.
public class CustomIssueEventHandler implements InitializingBean, DisposableBean {
private final EventPublisher publisher;
public CustomIssueEventHandler(EventPublisher publisher) {
this.publisher = publisher;
}
@Override
public void afterPropertiesSet() throws Exception {
publisher.register(this);
}
@Override
public void destroy() throws Exception {
publisher.unregister(this);
}
@EventListener
public void handleIssueEvent(IssueEvent event) {
// Custom email processing logic goes here
}
}
For the email template processing, I’m trying to leverage JIRA’s built-in velocity templates:
ApplicationProperties appProps = ComponentAccessor.getApplicationProperties();
String siteUrl = appProps.getString(APKeys.JIRA_BASEURL);
String encoding = appProps.getString(APKeys.JIRA_WEBWORK_ENCODING);
VelocityManager velocityMgr = ComponentAccessor.getVelocityManager();
VelocityParamFactory paramFactory = ComponentAccessor.getVelocityParamFactory();
Map templateContext = paramFactory.getDefaultVelocityParams();
templateContext.put("siteurl", siteUrl);
templateContext.put("timestamp", new Date());
templateContext.put("issue", event.getIssue());
String emailContent = velocityMgr.getEncodedBody("templates/email/html/", "issueresolved.vm", siteUrl, encoding, templateContext);
SMTPMailServer server = MailFactory.getServerManager().getDefaultSMTPMailServer();
Email notification = new Email("[email protected]");
notification.setMimeType("text/html");
notification.setEncoding("utf-8");
notification.setBody(emailContent);
try {
server.send(notification);
} catch (MailException ex) {
ex.printStackTrace();
}
The template renders partially but I’m missing styling, images and internationalization elements. What’s the proper way to include these components when reusing JIRA’s email templates? Is there a better approach than manually processing velocity templates?