
net.emphased.malle.example.freemarker.FreemarkerExample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of malle-freemarker-example Show documentation
Show all versions of malle-freemarker-example Show documentation
Example of using Freemarker template for composing a mail
The newest version!
package net.emphased.malle.example.freemarker;
import freemarker.template.Configuration;
import freemarker.template.TemplateExceptionHandler;
import net.emphased.malle.MailException;
import net.emphased.malle.example.AbstractExample;
import net.emphased.malle.javamail.Javamail;
import net.emphased.malle.template.freemarker.FreemarkerTemplateEngine;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public final class FreemarkerExample extends AbstractExample {
public static void main(String[] args) throws IOException {
Configuration fc = new Configuration(Configuration.VERSION_2_3_22);
fc.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
fc.setDefaultEncoding("UTF-8");
String template = checkNotNull(System.getProperty("template"), "Please set 'template' property");
System.out.println("Sending mail using '" + template + "' template");
if (template.startsWith("classpath:")) {
template = template.substring("classpath:".length());
fc.setClassForTemplateLoading(FreemarkerExample.class, "/");
} else {
Path path = Paths.get(template);
template = path.getFileName().toString();
fc.setDirectoryForTemplateLoading(path.getParent().toFile());
}
Map c = new HashMap<>();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy