}
@Override
public boolean sendDomainAccessRequestEmail(Long domainRequestId) {
boolean emailsSent = false;
WebRequest webRequest = WebRequest.getInstance();
if (sendEmail && webRequest != null && domainRequestId != null) {
DomainRequest domainRequest = domainRequestService.get(domainRequestId);
if(domainRequest == null) {
log.error("No DomainUserRequest found with ID: " + domainRequestId);
return true;
}
if(domainRequest.getDomain() == null) {
log.error("No Domain found for DomainRequest with ID: " + domainRequestId);
return true;
}
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
try {
int numberOfEmails = 0;
message.setSubject("Knappsack: Domain Request");
Locale locale = LocaleContextHolder.getLocale();
message.setFrom(fromAddress);
int emailCount = 0;
Region region = domainRequest.getRegion();
if (region != null && region.getEmails() != null && region.getEmails().size() > 0) {
emailCount = region.getEmails().size();
for (String email : region.getEmails()) {
Context ctx = new Context(locale);
ctx.setVariable("url", webRequest.generateURL("/manager/requestsPending/" + domainRequest.getDomain().getId()));
ctx.setVariable("domain", domainRequest.getDomain());
ctx.setVariable("requesterFirstName", domainRequest.getFirstName());
ctx.setVariable("requesterLastName", domainRequest.getLastName());
ctx.setVariable("requesterEmail", domainRequest.getEmailAddress());
ctx.setVariable("requesterAddress", domainRequest.getAddress());
ctx.setVariable("requesterCompanyName", domainRequest.getCompanyName());
ctx.setVariable("requesterPhone", domainRequest.getPhoneNumber());
ctx.setVariable("requesterDeviceType", domainRequest.getDeviceType());
ctx.setVariable("requesterRegion", domainRequest.getRegion());
List<Language> languages = new ArrayList<Language>();
languages.addAll(domainRequest.getLanguages());
Collections.sort(languages, new LanguageComparator());
ctx.setVariable("requesterLanguages", languages);
applyBranding(domainRequest.getDomain(), ctx);
// Create the HTML body using Thymeleaf
final String htmlContent = this.templateEngine.process("email-domainAccessRequestTH", ctx);
message.setText(htmlContent, true /* isHtml */);
message.setTo(email);
if (sendMessage(mimeMessage)) {
numberOfEmails += 1;
}
}
} else {
List<User> users = domainService.getAllAdmins(domainRequest.getDomain(), true);
emailCount = (users == null ? 0 : users.size());
if (users != null) {
for (User user : users) {
Context ctx = new Context(locale);
ctx.setVariable("url", webRequest.generateURL("/manager/requestsPending/" + domainRequest.getDomain().getId()));
ctx.setVariable("domain", domainRequest.getDomain());
ctx.setVariable("requesterFirstName", domainRequest.getFirstName());
ctx.setVariable("requesterLastName", domainRequest.getLastName());
ctx.setVariable("requesterEmail", domainRequest.getEmailAddress());
ctx.setVariable("requesterAddress", domainRequest.getAddress());