@Test public void testSendEmailWithEmbeddedLinks() throws Exception { final String email = "user_email"; final String header = "header"; final String baseUrl = "base_url"; final String title = "title"; final String footer = "footer"; final long fileId = 1234; final String token = "token"; final String note = header + "\\s*" + "<br/>" + baseUrl + fileId + "&acm_email_ticket=" + token + "<br/>" + "\\s*" + footer; List<String> addresses = new ArrayList<>(); addresses.add(email); List<Long> fileIds = new ArrayList<>(); fileIds.add(fileId); EmailWithEmbeddedLinksDTO inputDTO = new EmailWithEmbeddedLinksDTO(); inputDTO.setTitle(title); inputDTO.setHeader(header); inputDTO.setEmailAddresses(addresses); inputDTO.setBaseUrl(baseUrl); inputDTO.setFileIds(fileIds); inputDTO.setFooter(footer); senderConfig.setEncryption("off"); when(mockAcmEmailContentGeneratorService.generateEmailBody(inputDTO, email, mockAuthentication)).thenReturn(note); when(mockAcmUser.getUserId()).thenReturn("ann-acm"); when(mockEcmFileService.findById(fileIds.get(0))).thenReturn(mockEcmFile); List<EmailWithEmbeddedLinksResultDTO> results = service.sendEmailWithEmbeddedLinks(inputDTO, mockAuthentication, mockAcmUser); assertThat(results.size(), is(1)); EmailWithEmbeddedLinksResultDTO resultDTO = results.get(0); assertThat(resultDTO.isState(), is(true)); assertThat(resultDTO.getEmailAddress(), is(email)); verify(mockMailSender, times(1)).sendEmail(eq(email), anyString(), eq(note)); verify(mockApplicationEventPublisher).publishEvent(any(SmtpSentEventHyperlink.class)); }
@Override public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication, AcmUser user) { List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>(); Exception exception = null; Long parentId = setFilenames(in); for (String emailAddress : in.getEmailAddresses()) { try { acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication)); } catch (Exception e) { exception = e; } if (exception != null) { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false)); log.error("Email message not sent ...", exception); } else { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true)); } SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType()); boolean success = (exception == null); event.setSucceeded(success); eventPublisher.publishEvent(event); } return emailResultList; }
SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware { @Override public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication, AcmUser user) { List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>(); Exception exception = null; Long parentId = setFilenames(in); for (String emailAddress : in.getEmailAddresses()) { try { acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication)); } catch (Exception e) { exception = e; } if (exception != null) { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false)); log.error("Email message not sent ...", exception); } else { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true)); } SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType()); boolean success = (exception == null); event.setSucceeded(success); eventPublisher.publishEvent(event); } return emailResultList; } }
SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware { @Override public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication, AcmUser user) { List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>(); Exception exception = null; Long parentId = setFilenames(in); for (String emailAddress : in.getEmailAddresses()) { try { acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication)); } catch (Exception e) { exception = e; } if (exception != null) { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false)); log.error("Email message not sent ...", exception); } else { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true)); } SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType()); boolean success = (exception == null); event.setSucceeded(success); eventPublisher.publishEvent(event); } return emailResultList; }  }
SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware { @Override public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication, AcmUser user) { List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>(); Exception exception = null; Long parentId = setFilenames(in); for (String emailAddress : in.getEmailAddresses()) { try { acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication)); } catch (Exception e) { exception = e; } if (exception != null) { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false)); log.error("Email message not sent ...", exception); } else { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true)); } SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType()); boolean success = (exception == null); event.setSucceeded(success); eventPublisher.publishEvent(event); } return emailResultList; }  @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); @Override void sendPlainEmail(Stream<T> emailsDataStream, EmailBuilder<T> emailBuilder, EmailBodyBuilder<T> emailBodyBuilder); @Override void sendEmailWithAttachments(EmailWithAttachmentsDTO in, Authentication authentication, AcmUser user); @Override void sendEmail(EmailWithAttachmentsDTO in, Authentication authentication, AcmUser user); @Override void sendEmailWithAttachmentsAndLinks(EmailWithAttachmentsAndLinksDTO in, Authentication authentication, AcmUser user); @Override void sendEmail(EmailWithAttachmentsAndLinksDTO in, Authentication authentication, AcmUser user); @Override List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication,
            AcmUser user); void setEcmFileService(EcmFileService ecmFileService); AcmEmailContentGeneratorService getAcmEmailContentGeneratorService(); void setAcmEmailContentGeneratorService(AcmEmailContentGeneratorService acmEmailContentGeneratorService); EmailSenderConfig getEmailSenderConfig(); void setEmailSenderConfig(EmailSenderConfig emailSenderConfig); TemplatingEngine getTemplatingEngine(); void setTemplatingEngine(TemplatingEngine templatingEngine); DefaultFolderAndFileConverter getDefaultFolderAndFileConverter(); void setDefaultFolderAndFileConverter(DefaultFolderAndFileConverter defaultFolderAndFileConverter); AcmMailSender getAcmMailSender(); void setAcmMailSender(AcmMailSender acmMailSender); }
SmtpService implements AcmEmailSenderService, ApplicationEventPublisherAware { @Override public List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication, AcmUser user) { List<EmailWithEmbeddedLinksResultDTO> emailResultList = new ArrayList<>(); Exception exception = null; Long parentId = setFilenames(in); for (String emailAddress : in.getEmailAddresses()) { try { acmMailSender.sendEmail(emailAddress, in.getSubject(), makeNote(emailAddress, in, authentication)); } catch (Exception e) { exception = e; } if (exception != null) { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, false)); log.error("Email message not sent ...", exception); } else { emailResultList.add(new EmailWithEmbeddedLinksResultDTO(emailAddress, true)); } SmtpSentEventHyperlink event = new SmtpSentEventHyperlink(in, user.getUserId(), parentId, in.getParentType()); boolean success = (exception == null); event.setSucceeded(success); eventPublisher.publishEvent(event); } return emailResultList; }  @Override void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher); @Override void sendPlainEmail(Stream<T> emailsDataStream, EmailBuilder<T> emailBuilder, EmailBodyBuilder<T> emailBodyBuilder); @Override void sendEmailWithAttachments(EmailWithAttachmentsDTO in, Authentication authentication, AcmUser user); @Override void sendEmail(EmailWithAttachmentsDTO in, Authentication authentication, AcmUser user); @Override void sendEmailWithAttachmentsAndLinks(EmailWithAttachmentsAndLinksDTO in, Authentication authentication, AcmUser user); @Override void sendEmail(EmailWithAttachmentsAndLinksDTO in, Authentication authentication, AcmUser user); @Override List<EmailWithEmbeddedLinksResultDTO> sendEmailWithEmbeddedLinks(EmailWithEmbeddedLinksDTO in, Authentication authentication,
            AcmUser user); void setEcmFileService(EcmFileService ecmFileService); AcmEmailContentGeneratorService getAcmEmailContentGeneratorService(); void setAcmEmailContentGeneratorService(AcmEmailContentGeneratorService acmEmailContentGeneratorService); EmailSenderConfig getEmailSenderConfig(); void setEmailSenderConfig(EmailSenderConfig emailSenderConfig); TemplatingEngine getTemplatingEngine(); void setTemplatingEngine(TemplatingEngine templatingEngine); DefaultFolderAndFileConverter getDefaultFolderAndFileConverter(); void setDefaultFolderAndFileConverter(DefaultFolderAndFileConverter defaultFolderAndFileConverter); AcmMailSender getAcmMailSender(); void setAcmMailSender(AcmMailSender acmMailSender);  }