All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ext.springboot.EmailAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package ext.springboot;

import io.soffa.foundation.support.email.EmailSender;
import io.soffa.foundation.support.email.EmailSenderFactory;
import io.soffa.foundation.support.email.Mailer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class EmailAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "app.mail")
    public EmailConfig createSmtpConfig() {
        return new EmailConfig();
    }

    @Bean
    @ConditionalOnMissingBean(EmailSender.class)
    public Mailer createEmailSender(EmailConfig config) {
        Map clients = new HashMap<>();
        if (config.getClients() != null) {
            for (Map.Entry e : config.getClients().entrySet()) {
                clients.put(e.getKey(), EmailSenderFactory.create(e.getValue(), config.getFrom()));
            }
        }
        return new Mailer(clients);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy