use of pl.morecraft.dev.settler.domain.EmailTemplate in project Settler by EmhyrVarEmreis.
the class EmailService method sendEmail.
@Async
public void sendEmail(List<String> to, EmailTemplate emailTemplate, Map<String, String> options) {
EmailTemplateTmp emailTemplateTmp = EmailTemplateTmp.from(emailTemplate);
for (Map.Entry<String, String> optionsEntry : options.entrySet()) {
emailTemplateTmp.subject = emailTemplateTmp.subject.replaceAll("\\$" + optionsEntry.getKey(), optionsEntry.getValue());
emailTemplateTmp.content = emailTemplateTmp.content.replaceAll("\\$" + optionsEntry.getKey(), optionsEntry.getValue());
}
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(to.toArray(new String[to.size()]));
message.setFrom(settlerProperties.getMail().getFromAddress());
message.setSubject(emailTemplateTmp.subject);
message.setText(emailTemplateTmp.content, true);
};
try {
mailSender.send(preparator);
} catch (Exception e) {
log.error("Error occurred during sendEmail", e);
}
}
use of pl.morecraft.dev.settler.domain.EmailTemplate in project Settler by EmhyrVarEmreis.
the class EmailService method sendNotificationEmailNewTransaction.
public void sendNotificationEmailNewTransaction(Transaction transaction) {
EmailTemplate emailTemplate = emailTemplateRepository.findOneByTypeAndLanguage(EmailTemplateType.NEW_TRANSACTION, Language.EN_GB);
if (emailTemplate != null) {
Stream.concat(transaction.getContractors() == null ? Stream.empty() : transaction.getContractors().stream(), transaction.getOwners() == null ? Stream.empty() : transaction.getOwners().stream()).filter(redistribution -> !redistribution.getId().getUser().getId().equals(transaction.getCreator().getId())).forEach(redistribution -> {
Map<String, String> options = new HashMap<>();
options.put("description", transaction.getDescription());
options.put("creator", transaction.getCreator().getLogin());
options.put("user", redistribution.getId().getUser().getFirstName());
options.put("transactionId", transaction.getReference());
options.put("value", String.format("%.2f", redistribution.getPercentage() * transaction.getValue() / 100.0));
options.put("total", String.format("%.2f", transaction.getValue()));
sendEmail(Collections.singletonList(redistribution.getId().getUser().getEmail()), emailTemplate, options);
});
}
}
Aggregations