@Test void testCreateMimeMessageWithExceptionInInputStream() throws Exception { InputStream inputStream = mock(InputStream.class); AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class); JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService); IOException ioException = new IOException("error"); when(inputStream.read(ArgumentMatchers.any(byte[].class), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())) .thenThrow(ioException); try { mailSender.createMimeMessage(inputStream); fail("MailPreparationException expected due to error while creating mail"); } catch (MailParseException e) { assertThat(e.getMessage().startsWith("Could not parse raw MIME content")) .isTrue(); assertThat(e.getCause().getCause()).isSameAs(ioException); } }
@Override public MimeMessage createMimeMessage() { if (ClassUtils.isPresent(SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader())) { Class<?> smartMimeMessage = ClassUtils.resolveClassName( SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader()); Constructor<?> constructor = ClassUtils.getConstructorIfAvailable( smartMimeMessage, Session.class, String.class, FileTypeMap.class); if (constructor != null) { Object mimeMessage = BeanUtils.instantiateClass(constructor, getSession(), this.defaultEncoding, this.defaultFileTypeMap); return (MimeMessage) mimeMessage; } } return new MimeMessage(getSession()); }
SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSender implements JavaMailSender { @Override public MimeMessage createMimeMessage() { if (ClassUtils.isPresent(SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader())) { Class<?> smartMimeMessage = ClassUtils.resolveClassName( SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader()); Constructor<?> constructor = ClassUtils.getConstructorIfAvailable( smartMimeMessage, Session.class, String.class, FileTypeMap.class); if (constructor != null) { Object mimeMessage = BeanUtils.instantiateClass(constructor, getSession(), this.defaultEncoding, this.defaultFileTypeMap); return (MimeMessage) mimeMessage; } } return new MimeMessage(getSession()); } }
SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSender implements JavaMailSender { @Override public MimeMessage createMimeMessage() { if (ClassUtils.isPresent(SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader())) { Class<?> smartMimeMessage = ClassUtils.resolveClassName( SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader()); Constructor<?> constructor = ClassUtils.getConstructorIfAvailable( smartMimeMessage, Session.class, String.class, FileTypeMap.class); if (constructor != null) { Object mimeMessage = BeanUtils.instantiateClass(constructor, getSession(), this.defaultEncoding, this.defaultFileTypeMap); return (MimeMessage) mimeMessage; } } return new MimeMessage(getSession()); } SimpleEmailServiceJavaMailSender(
			AmazonSimpleEmailService amazonSimpleEmailService); }
SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSender implements JavaMailSender { @Override public MimeMessage createMimeMessage() { if (ClassUtils.isPresent(SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader())) { Class<?> smartMimeMessage = ClassUtils.resolveClassName( SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader()); Constructor<?> constructor = ClassUtils.getConstructorIfAvailable( smartMimeMessage, Session.class, String.class, FileTypeMap.class); if (constructor != null) { Object mimeMessage = BeanUtils.instantiateClass(constructor, getSession(), this.defaultEncoding, this.defaultFileTypeMap); return (MimeMessage) mimeMessage; } } return new MimeMessage(getSession()); } SimpleEmailServiceJavaMailSender(
			AmazonSimpleEmailService amazonSimpleEmailService); void setJavaMailProperties(Properties javaMailProperties); void setSession(Session session); void setDefaultEncoding(String defaultEncoding); void setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap); @Override MimeMessage createMimeMessage(); @Override MimeMessage createMimeMessage(InputStream contentStream); @Override void send(MimeMessage mimeMessage); @SuppressWarnings("OverloadedVarargsMethod") @Override void send(MimeMessage... mimeMessages); @Override void send(MimeMessagePreparator mimeMessagePreparator); @SuppressWarnings("OverloadedVarargsMethod") @Override void send(MimeMessagePreparator... mimeMessagePreparators); }
SimpleEmailServiceJavaMailSender extends SimpleEmailServiceMailSender implements JavaMailSender { @Override public MimeMessage createMimeMessage() { if (ClassUtils.isPresent(SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader())) { Class<?> smartMimeMessage = ClassUtils.resolveClassName( SMART_MIME_MESSAGE_CLASS_NAME, ClassUtils.getDefaultClassLoader()); Constructor<?> constructor = ClassUtils.getConstructorIfAvailable( smartMimeMessage, Session.class, String.class, FileTypeMap.class); if (constructor != null) { Object mimeMessage = BeanUtils.instantiateClass(constructor, getSession(), this.defaultEncoding, this.defaultFileTypeMap); return (MimeMessage) mimeMessage; } } return new MimeMessage(getSession()); } SimpleEmailServiceJavaMailSender(
			AmazonSimpleEmailService amazonSimpleEmailService); void setJavaMailProperties(Properties javaMailProperties); void setSession(Session session); void setDefaultEncoding(String defaultEncoding); void setDefaultFileTypeMap(FileTypeMap defaultFileTypeMap); @Override MimeMessage createMimeMessage(); @Override MimeMessage createMimeMessage(InputStream contentStream); @Override void send(MimeMessage mimeMessage); @SuppressWarnings("OverloadedVarargsMethod") @Override void send(MimeMessage... mimeMessages); @Override void send(MimeMessagePreparator mimeMessagePreparator); @SuppressWarnings("OverloadedVarargsMethod") @Override void send(MimeMessagePreparator... mimeMessagePreparators);  }