@Test public void all_configured_all_set_to_mailsender() { configToTest.hostname="host1"; configToTest.hostPort=1234; configToTest.username="usr1"; configToTest.password="pwd1"; configToTest.smtpConfigString="mail.smtp.auth=true,mail.smtp.timeout=4321,mail.transport.protocol=smtp"; configToTest.getJavaMailSender(); verify(mockedMailSender).setPassword("pwd1"); verify(mockedMailSender).setUsername("usr1"); verify(mockedMailSender).setPort(1234); verify(mockedMailSender).setHost("host1"); assertEquals(3, properties.size()); assertEquals("smtp", properties.getProperty("mail.transport.protocol")); assertEquals("true", properties.getProperty("mail.smtp.auth")); assertEquals("4321", properties.getProperty("mail.smtp.timeout")); }
@Bean public JavaMailSender getJavaMailSender() { JavaMailSenderImpl mailSender = createMailSender(); mailSender.setHost(hostname); mailSender.setPort(hostPort); if (isNotEmpty(username)) { mailSender.setUsername(username); } if (isNotEmpty(password)) { mailSender.setPassword(password); } Properties props = mailSender.getJavaMailProperties(); try { Map<String, String> map = configConverter.convertToMap(smtpConfigString); for (String key : map.keySet()) { props.put(key, map.get(key)); } } catch (Exception e) { LOG.error("Was not able to apply given smtp configuration"); } return mailSender; }
SMTPServerConfiguration { @Bean public JavaMailSender getJavaMailSender() { JavaMailSenderImpl mailSender = createMailSender(); mailSender.setHost(hostname); mailSender.setPort(hostPort); if (isNotEmpty(username)) { mailSender.setUsername(username); } if (isNotEmpty(password)) { mailSender.setPassword(password); } Properties props = mailSender.getJavaMailProperties(); try { Map<String, String> map = configConverter.convertToMap(smtpConfigString); for (String key : map.keySet()) { props.put(key, map.get(key)); } } catch (Exception e) { LOG.error("Was not able to apply given smtp configuration"); } return mailSender; } }
SMTPServerConfiguration { @Bean public JavaMailSender getJavaMailSender() { JavaMailSenderImpl mailSender = createMailSender(); mailSender.setHost(hostname); mailSender.setPort(hostPort); if (isNotEmpty(username)) { mailSender.setUsername(username); } if (isNotEmpty(password)) { mailSender.setPassword(password); } Properties props = mailSender.getJavaMailProperties(); try { Map<String, String> map = configConverter.convertToMap(smtpConfigString); for (String key : map.keySet()) { props.put(key, map.get(key)); } } catch (Exception e) { LOG.error("Was not able to apply given smtp configuration"); } return mailSender; }  }
SMTPServerConfiguration { @Bean public JavaMailSender getJavaMailSender() { JavaMailSenderImpl mailSender = createMailSender(); mailSender.setHost(hostname); mailSender.setPort(hostPort); if (isNotEmpty(username)) { mailSender.setUsername(username); } if (isNotEmpty(password)) { mailSender.setPassword(password); } Properties props = mailSender.getJavaMailProperties(); try { Map<String, String> map = configConverter.convertToMap(smtpConfigString); for (String key : map.keySet()) { props.put(key, map.get(key)); } } catch (Exception e) { LOG.error("Was not able to apply given smtp configuration"); } return mailSender; }  @Bean JavaMailSender getJavaMailSender(); }
SMTPServerConfiguration { @Bean public JavaMailSender getJavaMailSender() { JavaMailSenderImpl mailSender = createMailSender(); mailSender.setHost(hostname); mailSender.setPort(hostPort); if (isNotEmpty(username)) { mailSender.setUsername(username); } if (isNotEmpty(password)) { mailSender.setPassword(password); } Properties props = mailSender.getJavaMailProperties(); try { Map<String, String> map = configConverter.convertToMap(smtpConfigString); for (String key : map.keySet()) { props.put(key, map.get(key)); } } catch (Exception e) { LOG.error("Was not able to apply given smtp configuration"); } return mailSender; }  @Bean JavaMailSender getJavaMailSender();  }