/** * Retrieves the contact email for a tenant. If the tenant is null ("global tenant"), then use the global site * settings * * @param tenant the tenant for which to get the contact email, or null for a global tenant * @return the found contact email or null if no contact email has been found */ private String getTenantContactEmail(Tenant tenant) { if (tenant == null) { return siteSettings.getContactEmail(); } else { return StringUtils.isNotBlank(tenant.getContactEmail()) ? tenant.getContactEmail() : generalSettings.getNotificationsEmail(); } }
@Override public Mail emailToTenant() { return new Mail().from(generalSettings.getNotificationsEmail()).to(context.getTenant().getContactEmail()); }
private void sendPasswordResetMail(User user, final String secret, AccountsSettings settings) { MailTemplate mailTemplate = new MailTemplate().template("password-reset").to(user.getEmail()) .from(generalSettings.getNotificationsEmail()); try { Map<String, Object> context = Maps.newHashMap(); for (UserDataSupplier supplier : userDataSuppliers.values()) { supplier.supply(user, context); } String passwordResetUriLink; if (!Strings.isNullOrEmpty(settings.getUserPasswordResetUriTemplate().getValue())) { passwordResetUriLink = settings.getUserPasswordResetUriTemplate().getValue(); } else { passwordResetUriLink = urlHelper.getContextWebURL("/login/reset-password/${resetKey}").toString(); } SimpleTemplateEngine templateEngine = new SimpleTemplateEngine(); groovy.text.Template uriTemplate = templateEngine.createTemplate(passwordResetUriLink); context.put("resetLink", uriTemplate.make(new HashMap() { { put("resetKey", secret); } }).toString()); context.put("siteName", siteSettings.getName()); mailTemplateService.sendTemplateMail(mailTemplate, context); } catch (MailException | ClassNotFoundException | IOException e) { logger.error("Failed to send validation email", e); } }
private void sendValidationMail(final User createdUser, AccountsSettings settings, Map<String, Object> additionalContext) { MailTemplate mailTemplate = new MailTemplate().template("account-validation").to(createdUser.getEmail()) .from(generalSettings.getNotificationsEmail()); try { Map<String, Object> context = Maps.newHashMap(); context.putAll(additionalContext); String validationUriTemplate; if (!Strings.isNullOrEmpty(settings.getUserValidationUriTemplate().getValue())) { validationUriTemplate = settings.getUserValidationUriTemplate().getValue(); } else { validationUriTemplate = urlHelper.getContextWebURL("/account/validation/${validationKey}").toString(); } SimpleTemplateEngine templateEngine = new SimpleTemplateEngine(); groovy.text.Template uriTemplate = templateEngine.createTemplate(validationUriTemplate); context.put("validationLink", uriTemplate.make(new HashMap() { { put("validationKey", createdUser.getValidationKey()); } }).toString()); context.put("siteName", siteSettings.getName()); mailTemplateService.sendTemplateMail(mailTemplate, context); } catch (MailException | ClassNotFoundException | IOException e) { logger.error("Failed to send validation email", e); } }
/** * @param tenant the tenant of the shop the customer checked out from * @param locale the main locale of the tenant * @return an optional notification email object, present if all information is there and valid and the template * exists, absent otherwise */ private MailTemplate getTenantNotificationEmail(Tenant tenant, Locale locale) { return new MailTemplate() .from(generalSettings.getNotificationsEmail()) .to(getTenantContactEmail(tenant)) .template("order-paid-tenant") .locale(locale); }