@Test public void sendMailWithTemplateAndInlinePicture() throws MessagingException, IOException, TemplateException, CannotSendEmailException, URISyntaxException { final Email email = getSimpleMail(); assertThat(email.getSentAt(), is(nullValue())); final String toBeOverriddenBody = email.getBody(); final String bodyToBeReturned = "<img src=\"100_percent_free.jpg\" />"; final String imageName = "100_percent_free.jpg"; when(templateService.mergeTemplateIntoString(any(String.class), any(Map.class))).thenReturn(bodyToBeReturned); final File inlineImageFile = new File(getClass().getClassLoader() .getResource("images" + File.separator + imageName).toURI()); final MimeMessage sentMessage = mailService.send(email, "never_called.ftl", Maps.newHashMap(), getInlinePicture(inlineImageFile, imageName)); assertThat(email.getSentAt(), not(is(nullValue()))); validateFrom(email, sentMessage); validateReplyTo(email, sentMessage); validateTo(email, sentMessage); validateCc(email, sentMessage); validateBcc(email, sentMessage); validateSubject(email, sentMessage); final String imageId = ((MimeBodyPart) (((MimeMultipart) sentMessage.getContent()).getBodyPart(0))).getContentID(); assertThat(((MimeMultipart) sentMessage.getContent()).getBodyPart(1).getContent(), allOf(not(is(toBeOverriddenBody)), not(is(bodyToBeReturned)), is("<img src=\"cid:" + imageId.substring(1, imageId.length() - 1) + "\" />"))); verify(templateService, times(1)).mergeTemplateIntoString(any(String.class), any(Map.class)); }
@Override public MimeMessage send(final @NonNull Email email) { email.setSentAt(new Date()); final MimeMessage mimeMessage = toMimeMessage(email); javaMailSender.send(mimeMessage); emailLogRenderer.info("Sent email {}.", email); return mimeMessage; }
DefaultEmailService implements EmailService { @Override public MimeMessage send(final @NonNull Email email) { email.setSentAt(new Date()); final MimeMessage mimeMessage = toMimeMessage(email); javaMailSender.send(mimeMessage); emailLogRenderer.info("Sent email {}.", email); return mimeMessage; } }
DefaultEmailService implements EmailService { @Override public MimeMessage send(final @NonNull Email email) { email.setSentAt(new Date()); final MimeMessage mimeMessage = toMimeMessage(email); javaMailSender.send(mimeMessage); emailLogRenderer.info("Sent email {}.", email); return mimeMessage; } @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final TemplateService templateService,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); }
DefaultEmailService implements EmailService { @Override public MimeMessage send(final @NonNull Email email) { email.setSentAt(new Date()); final MimeMessage mimeMessage = toMimeMessage(email); javaMailSender.send(mimeMessage); emailLogRenderer.info("Sent email {}.", email); return mimeMessage; } @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final TemplateService templateService,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); @Override MimeMessage send(final @NonNull Email email); MimeMessage send(final @NonNull Email email,
                            final @NonNull String template,
                            final Map<String, Object> modelObject,
                            final @NonNull InlinePicture... inlinePictures); }
DefaultEmailService implements EmailService { @Override public MimeMessage send(final @NonNull Email email) { email.setSentAt(new Date()); final MimeMessage mimeMessage = toMimeMessage(email); javaMailSender.send(mimeMessage); emailLogRenderer.info("Sent email {}.", email); return mimeMessage; } @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final TemplateService templateService,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); @Autowired(required = false)  DefaultEmailService(final @NonNull JavaMailSender javaMailSender,
                               final @NonNull EmailToMimeMessage emailToMimeMessage,
                               final @NonNull EmailLogRenderer emailLogRenderer); @Override MimeMessage send(final @NonNull Email email); MimeMessage send(final @NonNull Email email,
                            final @NonNull String template,
                            final Map<String, Object> modelObject,
                            final @NonNull InlinePicture... inlinePictures);  }