Search in sources :

Example 1 with EmailException

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);
    }
}
Also used : EmailPreparationException(org.craftercms.commons.mail.EmailPreparationException) StringWriter(java.io.StringWriter) TemplateException(freemarker.template.TemplateException) EmailException(org.craftercms.commons.mail.EmailException) IOException(java.io.IOException) Template(freemarker.template.Template)

Example 2 with EmailException

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());
    }
}
Also used : I10nProfileException(org.craftercms.profile.api.exceptions.I10nProfileException) EmailException(org.craftercms.commons.mail.EmailException) Async(org.springframework.scheduling.annotation.Async)

Aggregations

EmailException (org.craftercms.commons.mail.EmailException)2 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 EmailPreparationException (org.craftercms.commons.mail.EmailPreparationException)1 I10nProfileException (org.craftercms.profile.api.exceptions.I10nProfileException)1 Async (org.springframework.scheduling.annotation.Async)1