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

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

Introduction

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

Prototype

public Properties getJavaMailProperties() 

Source Link

Document

Allow Map access to the JavaMail properties of this sender, with the option to add or override specific entries.

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));
            }// w  w w. ja  va  2  s . co 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)));
        }
    }
}