@Test void testCreateMailSenderWithoutUsernamePassword() { JavaMailSenderImpl actual = javaMailSenderFactory.createMailSender(mailSettings); assertEquals("host", actual.getHost()); assertEquals(1234, actual.getPort()); assertEquals("UTF-8", actual.getDefaultEncoding()); final Properties actualProperties = actual.getJavaMailProperties(); assertEquals("true", actualProperties.getProperty("mail.smtp.starttls.enable")); assertEquals("false", actualProperties.getProperty("mail.smtp.quitwait")); assertEquals("true", actualProperties.getProperty("mail.smtp.auth")); }
@Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; }
JavaMailSenderFactory implements MailSenderFactory { @Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; } }
JavaMailSenderFactory implements MailSenderFactory { @Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; }  }
JavaMailSenderFactory implements MailSenderFactory { @Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; }  @Override JavaMailSenderImpl createMailSender(MailSettings mailSettings); @Override void validateConnection(MailSettings mailSettings); }
JavaMailSenderFactory implements MailSenderFactory { @Override public JavaMailSenderImpl createMailSender(MailSettings mailSettings) { LOG.trace("createMailSender"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(mailSettings.getHost()); mailSender.setPort(mailSettings.getPort()); mailSender.setProtocol(mailSettings.getProtocol()); mailSender.setUsername(mailSettings.getUsername()); mailSender.setPassword(mailSettings.getPassword()); mailSender.setDefaultEncoding(mailSettings.getDefaultEncoding().name()); Properties properties = new Properties(defaultProperties); defaultProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, mailSettings.isStartTlsEnabled()); defaultProperties.setProperty(MAIL_SMTP_QUITWAIT, mailSettings.isQuitWait()); defaultProperties.setProperty(MAIL_SMTP_AUTH, mailSettings.isAuthenticationRequired()); defaultProperties.setProperty(MAIL_SMTP_FROM_ADDRESS, mailSettings.getFromAddress()); properties.putAll(mailSettings.getJavaMailProperties()); LOG.debug("Mail properties: {}; defaults: {}", properties, defaultProperties); mailSender.setJavaMailProperties(properties); return mailSender; }  @Override JavaMailSenderImpl createMailSender(MailSettings mailSettings); @Override void validateConnection(MailSettings mailSettings); static final String MAIL_SMTP_STARTTLS_ENABLE; static final String MAIL_SMTP_QUITWAIT; static final String MAIL_SMTP_AUTH; static final String MAIL_SMTP_FROM_ADDRESS; }