String password = propertyResolver.getProperty(PROP_PASSWORD);
String protocol = propertyResolver.getProperty(PROP_PROTO);
Boolean tls = propertyResolver.getProperty(PROP_TLS, Boolean.class, false);
Boolean auth = propertyResolver.getProperty(PROP_AUTH, Boolean.class, false);
JavaMailSenderImpl sender = new JavaMailSenderImpl();
if (host != null && !host.isEmpty()) {
sender.setHost(host);
} else {
log.warn("Warning! Your SMTP server is not configured. We will try to use one on localhost.");
log.debug("Did you configure your SMTP settings in your application.yml?");
sender.setHost(DEFAULT_HOST);
}
sender.setPort(port);
sender.setUsername(user);
sender.setPassword(password);
Properties sendProperties = new Properties();
sendProperties.setProperty(PROP_SMTP_AUTH, auth.toString());
sendProperties.setProperty(PROP_STARTTLS, tls.toString());
sendProperties.setProperty(PROP_TRANSPORT_PROTO, protocol);
sender.setJavaMailProperties(sendProperties);
return sender;
}