Java 如何在电子邮件中重用JIRA velocity模板?

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

我想更改JIRA的通知行为,并向某些问题事件添加其他接收者。我知道我可以注册
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等。?或者我可以使用不同的方法吗

有几个字段被填充了,但我仍然错过了CSS、图像或i18n

在实现插件的国际化(也称为“i18n”,因为“i”和“n”之间有18个字母)支持之前,了解插件是如何国际化的非常重要

首先,插件中的所有消息必须移动到代码之外的插件中的属性文件中。属性文件存储插件内所有消息的默认(英文)翻译。属性文件格式是key=value格式,其中key用于引用代码中的资源,而value是英语中的默认消息

对于每个资源,资源的位置应该与插件JAR文件中的资源路径相匹配。资源路径与插件同名,因此它们不会与具有相同位置的其他插件中的资源冲突(不像i18n或Velocity资源)。但是,您可能会发现使用特定于插件的路径名与这些其他类型保持一致很方便

要在使用插件的页面中包含自定义web资源,请使用#requireResource Velocity宏