private Email getEmail(String templatePath, Map<String, String> emailParams) {
ResourceResolver resourceResolver = null;
try {
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
final MailTemplate mailTemplate = MailTemplate.create(templatePath, resourceResolver.adaptTo(Session.class));
if (mailTemplate == null) {
log.warn("Email template at {} could not be created.", templatePath);
return null;
}
Class<? extends Email> emailClass = templatePath.endsWith(".html") ? HtmlEmail.class : SimpleEmail.class;
final Email email = mailTemplate.getEmail(StrLookup.mapLookup(emailParams), emailClass);
if (emailParams.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)
&& emailParams.containsKey(EmailServiceConstants.SENDER_NAME)) {
email.setFrom(emailParams.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS),
emailParams.get(EmailServiceConstants.SENDER_NAME));