package <%=packageName%>.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailConfiguration implements EnvironmentAware {

    private final Logger log = LoggerFactory.getLogger(MailConfiguration.class);

    private RelaxedPropertyResolver propertyResolver;

    public MailConfiguration() {
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.mail.");
    }

    @Bean
    public JavaMailSenderImpl javaMailSender() {
        log.debug("Configuring mail server");
        String host = propertyResolver.getProperty("host", "localhost");
        int port = propertyResolver.getProperty("port", Integer.class, 0);
        String user = propertyResolver.getProperty("user");
        String password = propertyResolver.getProperty("password");
        String protocol = propertyResolver.getProperty("protocol");
        Boolean tls = propertyResolver.getProperty("tls", Boolean.class, false);

        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        if (host != null && !host.equals("")) {
            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("127.0.0.1");
        } else {
            sender.setHost(host);
        }
        sender.setPort(port);
        sender.setUsername(user);
        sender.setPassword(password);

        Properties sendProperties = new Properties();
        sendProperties.setProperty("smtp.starttls.enable", tls ? "true" : "false");
        sendProperties.setProperty("mail.transport.protocol", protocol);
        sender.setJavaMailProperties(sendProperties);
        return sender;
    }
}

@@ -530,16 +530,809 @@
 ware %7B%0A%0A
+    private static final String ENV_SPRING_MAIL = %22spring.mail.%22;%0A    private static final String DEFAULT_HOST = %22127.0.0.1%22;%0A    private static final String PROP_HOST = %22host%22;%0A    private static final String DEFAULT_PROP_HOST = %22localhost%22;%0A    private static final String PROP_PORT = %22port%22;%0A    private static final String PROP_USER = %22user%22;%0A    private static final String PROP_PASSWORD = %22password%22;%0A    private static final String PROP_PROTO = %22protocol%22;%0A    private static final String PROP_TLS = %22tls%22;%0A    private static final String PROP_AUTH = %22auth%22;%0A    private static final String PROP_SMTP_AUTH = %22mail.smtp.auth%22;%0A    private static final String PROP_STARTTLS = %22mail.smtp.starttls.enable%22;%0A    private static final String PROP_TRANSPORT_PROTO = %22mail.transport.protocol%22;%0A%0A
     priv
@@ -1645,30 +1645,31 @@
 onment, 
-%22spring.mail.%22
+ENV_SPRING_MAIL
 );%0A    %7D
@@ -1830,27 +1830,36 @@
 rty(
-%22host%22, %22localhost%22
+PROP_HOST, DEFAULT_PROP_HOST
 );%0A 
@@ -1905,22 +1905,25 @@
 roperty(
-%22port%22
+PROP_PORT
 , Intege
@@ -1986,22 +1986,25 @@
 roperty(
-%22user%22
+PROP_USER
 );%0A     
@@ -2053,26 +2053,29 @@
 roperty(
-%22password%22
+PROP_PASSWORD
 );%0A     
@@ -2124,26 +2124,110 @@
 roperty(
-%22protocol%22
+PROP_PROTO);%0A        Boolean tls = propertyResolver.getProperty(PROP_TLS, Boolean.class, false
 );%0A     
@@ -2229,35 +2229,36 @@
         Boolean 
-tls
+auth
  = propertyResol
@@ -2273,21 +2273,25 @@
 roperty(
-%22tls%22
+PROP_AUTH
 , Boolea
@@ -2408,19 +2408,69 @@
 ost.
-equals(%22%22))
+isEmpty()) %7B%0A            sender.setHost(host);%0A        %7D else
  %7B%0A 
@@ -2694,70 +2694,20 @@
 ost(
-%22127.0.0.1%22);%0A        %7D else %7B%0A            sender.setHost(host
+DEFAULT_HOST
 );%0A 
@@ -2911,117 +2911,164 @@
 rty(
-%22smtp.starttls.enable%22, tls ? %22true%22 : %22false%22);%0A        sendProperties.setProperty(%22mail.transport.protocol%22
+PROP_SMTP_AUTH, auth.toString());%0A        sendProperties.setProperty(PROP_STARTTLS, tls.toString());%0A        sendProperties.setProperty(PROP_TRANSPORT_PROTO
 , pr

Update _MailConfiguration.java