@Test public void defaults() { configToTest.hostname="host1"; configToTest.getJavaMailSender(); verify(mockedMailSender,never()).setPassword(any()); verify(mockedMailSender,never()).setUsername(any()); verify(mockedMailSender).setHost("host1"); verify(mockedMailSender).setPort(SMTPServerConfiguration.DEFAULT_SMTP_SERVER_PORT); assertEquals(2, properties.size()); assertEquals("smtp", properties.getProperty("mail.transport.protocol")); assertEquals("false", properties.getProperty("mail.smtp.auth")); }
@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();  }