use of org.craftercms.commons.mail.EmailException in project commons by craftercms.
the class EmailFactoryImpl method processTemplate.
protected String processTemplate(String templateName, Object templateModel) throws EmailException {
if (freeMarkerConfig == null) {
throw new EmailException(ERROR_KEY_TEMPLATE_CONFIG_MISSING);
}
templateName = templatePrefix + templateName + templateSuffix;
logger.debug(LOG_KEY_PROCESSING_EMAIL_TEMPLATE, templateName);
try {
Template template = freeMarkerConfig.getTemplate(templateName, templateEncoding);
StringWriter out = new StringWriter();
template.process(templateModel, out);
return out.toString();
} catch (IOException | TemplateException e) {
throw new EmailPreparationException(e);
}
}
use of org.craftercms.commons.mail.EmailException in project profile by craftercms.
the class VerificationServiceImpl method sendEmail.
@Override
@Async
public void sendEmail(VerificationToken token, Profile profile, String verificationBaseUrl, String from, String subject, String templateName) throws ProfileException {
String verificationUrl = createVerificationUrl(verificationBaseUrl, token.getId().toString());
Map<String, String> templateArgs = Collections.singletonMap(VERIFICATION_LINK_TEMPLATE_ARG, verificationUrl);
String[] to = new String[] { profile.getEmail() };
try {
emailFactory.getEmail(from, to, null, null, subject, templateName, templateArgs, true).send();
logger.debug(LOG_KEY_EMAIL_SENT, profile.getId(), profile.getEmail());
} catch (EmailException e) {
throw new I10nProfileException(ERROR_KEY_EMAIL_ERROR, e, profile.getEmail());
}
}
Aggregations