如何在Spring中配置多个插入图像FTL templamaker

时间:2018-08-14 11:26:32

标签: java spring spring-boot

我的项目中有3个带有徽标的ftl模板,但是只有1个徽标正在工作,这是确认。我要做的基本上是,当用户单击验证链接时,应该显示我的徽标,它与确认徽标相同

我下面的代码;

@Component
public class EmailSender {

    @Autowired
    JavaMailSender javaEmailSender;

    public void sendEmail(String to, String subject, String text) throws MessagingException {
        MimeMessage message = javaEmailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
                StandardCharsets.UTF_8.name());
        helper.setTo(to);
        helper.setSubject(subject);
        helper.setText(text, true);
        helper.addInline("logo.jpg", new ClassPathResource("./images/logo.jpg"));
        javaEmailSender.send(message);
    }

我的电子邮件模板加载器

@Autowired
    private Configuration freemakerConfiguration;

    public String getEmailBody(String name, String confirmationLink) throws TemplateException {

        try {
            Template template = freemakerConfiguration.getTemplate("EmailConfirmation.ftl");

            Map<String, Object> data = new HashMap<String, Object>();
            data.put("name", name);
            data.put("confirmationLink", confirmationLink);

            return FreeMarkerTemplateUtils.processTemplateIntoString(template, data);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        }
        return "";

0 个答案:

没有答案