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;
}
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;
}
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;
}
Aggregations