Example usage for org.springframework.mail.javamail JavaMailSenderImpl getSession

List of usage examples for org.springframework.mail.javamail JavaMailSenderImpl getSession

Introduction

In this page you can find the example usage for org.springframework.mail.javamail JavaMailSenderImpl getSession.

Prototype

public synchronized Session getSession() 

Source Link

Document

Return the JavaMail Session , lazily initializing it if hasn't been specified explicitly.

Usage

From source file:org.apache.syncope.core.provisioning.java.job.notification.NotificationJobDelegate.java

@Override
public void afterPropertiesSet() throws Exception {
    if (mailSender instanceof JavaMailSenderImpl) {
        JavaMailSenderImpl javaMailSender = (JavaMailSenderImpl) mailSender;

        Properties javaMailProperties = javaMailSender.getJavaMailProperties();

        Properties props = PropertyUtils.read(Encryptor.class, "mail.properties", "conf.directory").getLeft();
        for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
            String prop = (String) e.nextElement();
            if (prop.startsWith("mail.smtp.")) {
                javaMailProperties.setProperty(prop, props.getProperty(prop));
            }//  ww  w  .j ava  2s  . c o  m
        }

        if (StringUtils.isNotBlank(javaMailSender.getUsername())) {
            javaMailProperties.setProperty("mail.smtp.auth", "true");
        }

        javaMailSender.setJavaMailProperties(javaMailProperties);

        String mailDebug = props.getProperty("mail.debug", "false");
        if (BooleanUtils.toBoolean(mailDebug)) {
            Session session = javaMailSender.getSession();
            session.setDebug(true);
            session.setDebugOut(new PrintStream(new LogOutputStream(LOG)));
        }
    }
}