خرید بک لینک

Vote count: 0

I am sending an html email with integration of Spring + velocity

Here is my code:

   javaMailSender.send(new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setFrom(from);
            message.setTo(to);
            message.setSubject(subject);

            //set properties
            velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
            velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
            velocityEngine.init();

            //velocity context
            VelocityContext context = new VelocityContext();
            context.put("firstName", firstName);

            //set template
            Template template = velocityEngine.getTemplate("templates/EmailTemplate.vm");
            StringWriter writer = new StringWriter();
            template.merge(context, writer);

            message.setText(writer.toString(), true);
        }
    });

And my EmailTemplate.vm is in the resources/templates/EmailTemplate.vm

<!DOCTYPE html>
<html>
<body>
<h1>Spring by Example</h1>
<p>Welcome ${firstName}</p>
<p>Thank you for joining the site.</p>
</body>
</html>

I can successfully send email, but i received it as plain text in my gmail.

asked 49 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 9 خرداد 1395 ساعت: 19:23

صفحه بندی