Search in sources :

Example 1 with EmailBuilder

use of io.gravitee.am.common.email.EmailBuilder in project gravitee-access-management by gravitee-io.

the class EmailServiceImpl method createEmail.

@Override
public EmailWrapper createEmail(io.gravitee.am.model.Template template, Client client, List<String> recipients, Map<String, Object> params) throws IOException, TemplateException {
    io.gravitee.am.model.Email emailTpl = getEmailTemplate(template, client);
    params.put("expireAfterSeconds", emailTpl.getExpiresAfter());
    final long expiresAt = Instant.now().plus(emailTpl.getExpiresAfter(), ChronoUnit.SECONDS).toEpochMilli();
    params.put("expireAt", expiresAt);
    io.gravitee.am.common.email.Email email = new EmailBuilder().from(emailTpl.getFrom()).fromName(emailTpl.getFromName()).template(emailTpl.getTemplate()).to(recipients.toArray(new String[recipients.size()])).build();
    // compute email subject
    final Template plainTextTemplate = new Template("subject", new StringReader(emailTpl.getSubject()), freemarkerConfiguration);
    email.setSubject(processTemplateIntoString(plainTextTemplate, params));
    // compute email content
    final Template subjectTemplate = freemarkerConfiguration.getTemplate(email.getTemplate());
    email.setContent(processTemplateIntoString(subjectTemplate, params));
    EmailWrapper wrapper = new EmailWrapper(email);
    wrapper.setExpireAt(expiresAt);
    return wrapper;
}
Also used : Email(io.gravitee.am.common.email.Email) StringReader(java.io.StringReader) EmailBuilder(io.gravitee.am.common.email.EmailBuilder) Template(freemarker.template.Template)

Example 2 with EmailBuilder

use of io.gravitee.am.common.email.EmailBuilder in project gravitee-access-management by gravitee-io.

the class EmailServiceImpl method prepareEmail.

private Email prepareEmail(io.gravitee.am.model.Template template, io.gravitee.am.model.Email emailTemplate, User user, Client client) {
    Map<String, Object> params = prepareEmailParams(user, client, emailTemplate.getExpiresAfter(), template.redirectUri());
    Email email = new EmailBuilder().to(user.getEmail()).from(emailTemplate.getFrom()).fromName(emailTemplate.getFromName()).subject(emailTemplate.getSubject()).template(emailTemplate.getTemplate()).params(params).build();
    return email;
}
Also used : Email(io.gravitee.am.common.email.Email) FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) EmailBuilder(io.gravitee.am.common.email.EmailBuilder)

Example 3 with EmailBuilder

use of io.gravitee.am.common.email.EmailBuilder in project gravitee-access-management by gravitee-io.

the class EmailServiceImpl method prepareEmail.

private Email prepareEmail(Domain domain, Application client, io.gravitee.am.model.Template template, io.gravitee.am.model.Email emailTemplate, User user) {
    Map<String, Object> params = prepareEmailParams(domain, client, user, emailTemplate.getExpiresAfter(), template.redirectUri());
    Email email = new EmailBuilder().to(user.getEmail()).from(emailTemplate.getFrom()).fromName(emailTemplate.getFromName()).subject(emailTemplate.getSubject()).template(emailTemplate.getTemplate()).params(params).build();
    return email;
}
Also used : Email(io.gravitee.am.common.email.Email) FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) EmailBuilder(io.gravitee.am.common.email.EmailBuilder)

Aggregations

Email (io.gravitee.am.common.email.Email)3 EmailBuilder (io.gravitee.am.common.email.EmailBuilder)3 FreeMarkerTemplateUtils.processTemplateIntoString (org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString)2 Template (freemarker.template.Template)1 StringReader (java.io.StringReader)1