Java 如何在电子邮件中重用JIRA velocity模板?
我想更改JIRA的通知行为,并向某些问题事件添加其他接收者。我知道我可以注册Java 如何在电子邮件中重用JIRA velocity模板?,java,email,templates,jira,velocity,Java,Email,Templates,Jira,Velocity,我想更改JIRA的通知行为,并向某些问题事件添加其他接收者。我知道我可以注册EventPublisher并捕获所有必要的事件 public class MyIssueCreatedResolvedListenerImpl implements InitializingBean, DisposableBean { private final EventPublisher eventPublisher; public MyIssueCreatedResolvedListenerIm
EventPublisher
并捕获所有必要的事件
public class MyIssueCreatedResolvedListenerImpl implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;
public MyIssueCreatedResolvedListenerImpl(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
// Process the issue events. I'm using the code presented below.
}
}
在onIssueEvent
中,我想重用JIRA的现有电子邮件模板,并将它们与SMTPMailServer
对象一起发送给其他接收者。目前,我正在使用以下代码来阅读和填充velocity模板
ApplicationProperties ap = ComponentAccessor.getApplicationProperties();
String baseUrl = ap.getString(APKeys.JIRA_BASEURL);
String webworkEncoding = ap.getString(APKeys.JIRA_WEBWORK_ENCODING);
VelocityManager vm = ComponentAccessor.getVelocityManager();
VelocityParamFactory vp = ComponentAccessor.getVelocityParamFactory();
Map context = vp.getDefaultVelocityParams();
context.put("baseurl", baseUrl);
context.put("currentTimestamp", new Date());
context.put("issue", issueEvent.getIssue());
String renderedText = vm.getEncodedBody("templates/email/html/", "issueclosed.vm", baseUrl, webworkEncoding, context);
SMTPMailServer mailServer = MailFactory.getServerManager().getDefaultSMTPMailServer();
Email email = new Email("<E-Mail-Adress>");
email.setMimeType("text/html");
email.setEncoding("utf-8");
email.setBody(renderedText);
try {
mailServer.send(email);
} catch (MailException e) {
e.printStackTrace();
}
ApplicationProperties ap=ComponentAccessor.getApplicationProperties();
String baseUrl=ap.getString(APKeys.JIRA_baseUrl);
String webworkEncoding=ap.getString(APKeys.JIRA\u WEBWORK\u ENCODING);
VelocityManager vm=ComponentAccessor.getVelocityManager();
VelocityParamFactory vp=ComponentAccessor.getVelocityParamFactory();
Map context=vp.getDefaultVelocityParams();
context.put(“baseurl”,baseurl);
put(“currentTimestamp”,new Date());
put(“issue”,issueEvent.getIssue());
String renderedText=vm.getEncodedBody(“templates/email/html/”、“issueclosed.vm”、baseUrl、webworkEncoding、context);
SMTPMailServer mailServer=MailFactory.getServerManager().getDefaultSMTPMailServer();
电子邮件=新电子邮件(“”);
email.setMimeType(“text/html”);
电子邮件。设置编码(“utf-8”);
email.setBody(呈现文本);
试一试{
mailServer.send(电子邮件);
}捕获(邮件例外){
e、 printStackTrace();
}
上面的代码部分工作。虽然填写了几个字段,但我仍然没有看到电子邮件通知中的CSS、图像或i18n。请注意,我不会使用来自市场的任何附加组件
- 这是重用JIRA模板的正确实现吗
- 如何包含CSS、图像、i18n等。?或者我可以使用不同的方法吗