Using Apache FreeMarker for templates

Apache FreeMarker is used to generate the HTML body that will be embedded in the body of the email that will be sent when reset password requests are received. The following template, src/resources/templates/reset_password_en.html, is used:

<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Reset Password</title>
<style>
/** Styling Code **/
</style>
</head>
<body class="">
<table border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td>&nbsp;</td>
<td class="container">
<div class="content">

<!-- START CENTERED WHITE CONTAINER -->
<span class="preheader">This email is sent to reset the password of ${USERNAME}.</span>
<table class="main">

<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<p>Hi ${USERNAME},</p>
<p>Your password has been reset. Your new password is following.</p>
<table border="0" cellpadding="0" cellspacing="0" class="btn btn-primary">
<tbody>
<tr>
<td align="left">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>${NEW_PASSWORD}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p>Please re-login and change the password so that it will be your secret.</p>
<p>Good luck! Hope it works.</p>
</td>
</tr>
</table>
</td>
</tr>

<!-- END MAIN CONTENT AREA -->
</table>

<!-- START FOOTER -->
<div class="footer">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">
<span class="apple-link">Packtpub.com</span>
</td>
</tr>
<tr>
<td class="content-block powered-by">
Powered by Shazin Sadakath.
</td>
</tr>
</table>
</div>
<!-- END FOOTER -->

<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>

This is a standard HTML page with the custom placeholders ${USERNAME} and ${NEW_PASSWORD}, which will be populated by the following EmailTemplateService:

@Service
public class EmailTemplateService {

private final Configuration configuration;

public EmailTemplateService(Configuration configuration) {
this.configuration = configuration;
}

public String getResetPasswordEmail(Map<String, Object> data, String templateName) throws IOException, TemplateException {
Template template = configuration.getTemplate(templateName);
return FreeMarkerTemplateUtils.processTemplateIntoString(template, data);
}

}

When the getResetPasswordEmail method is called with Map of data and a template name, it will load the template and replace the placeholders with the actual value from Map. The template is derived from https://github.com/leemunroe/responsive-html-email-template.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.157.142