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

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

Introduction

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

Prototype

public JavaMailSenderImpl() 

Source Link

Document

Create a new instance of the JavaMailSenderImpl class.

Usage

From source file:br.com.semanticwot.cd.conf.AppWebConfiguration.java

@Bean
public JavaMailSenderImpl mailSender() { // para consegui fazer a injeo automtica

    JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
    javaMailSenderImpl.setHost("smtp.gmail.com");
    javaMailSenderImpl.setPassword("senhadeapp");
    javaMailSenderImpl.setPort(587);/*  w  w  w .  j a v a2  s. com*/
    javaMailSenderImpl.setUsername("wiser");
    Properties mailProperties = new Properties();
    mailProperties.put("mail.smtp.auth", true);
    mailProperties.put("mail.smtp.starttls.enable", true);
    javaMailSenderImpl.setJavaMailProperties(mailProperties);

    return javaMailSenderImpl;
}

From source file:dk.nsi.haiba.epimibaimporter.config.EPIMIBAConfiguration.java

@Bean
public JavaMailSender javaMailSender() {
    Properties javaMailProperties = new Properties();
    javaMailProperties.put("mail.smtp.auth", smtpAuth);
    javaMailProperties.put("mail.smtp.starttls.enable", smtpStartTLS);
    javaMailProperties.put("mail.smtp.host", smtpHost);
    javaMailProperties.put("mail.smtp.port", smtpPort);

    JavaMailSenderImpl sender = new JavaMailSenderImpl();
    sender.setJavaMailProperties(javaMailProperties);
    if (smtpAuth) {
        sender.setUsername(smtpUser);/*  w  ww  .ja  v a  2 s  .  c o  m*/
        sender.setPassword(smtpPassword);
    }
    return sender;
}

From source file:edu.wisc.jmeter.MonitorListener.java

@Override
public void testStarted() {
    this.connectionPool = new DataSource();
    this.connectionPool.setDriverClassName(this.jdbcDriver);
    this.connectionPool.setUrl(this.jdbcUrl);
    this.connectionPool.setUsername(this.jdbcUser);
    this.connectionPool.setPassword(this.jdbcPass);
    this.connectionPool.setValidationQuery("SELECT 1 FROM DUAL");
    this.connectionPool.setTestOnBorrow(true);
    this.connectionPool.setTestWhileIdle(true);
    this.connectionPool.setJdbcInterceptors("ConnectionState(useEquals=true);ResetAbandonedTimer");

    log.info("Created DB pool for: {" + this.jdbcDriver + ", " + this.jdbcUrl + ", " + this.jdbcUser + "}");

    this.jdbcMonitorDao = new JdbcMonitorDao(this.connectionPool, this.purgeOldFailure, this.purgeOldStatus);
    try {/*from   w w  w. j  a  v  a  2s  .c  om*/
        this.jdbcMonitorDao.afterPropertiesSet();
        this.monitorDao = new ErrorHandlingMonitorDao(this.jdbcMonitorDao);
    } catch (Exception e) {
        throw new RuntimeException("Failed to initialize JdbcMonitorDao", e);
    }
    log.info("Created JdbcMonitorDao");

    final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(this.smtpHost);
    this.javaMailSender = mailSender;
    log.info("Created JavaMailSender for: {" + this.smtpHost + "}");
}

From source file:info.jtrac.mail.MailSender.java

private void initMailSenderFromJndi(String mailSessionJndiName) {
    logger.info("attempting to initialize mail sender from jndi name = '" + mailSessionJndiName + "'");
    JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
    factoryBean.setJndiName(mailSessionJndiName);
    // "java:comp/env/" will be prefixed if the JNDI name doesn't already have it
    factoryBean.setResourceRef(true);//w  ww  . j  av  a  2 s  . co  m
    try {
        // this step actually does the JNDI lookup
        factoryBean.afterPropertiesSet();
    } catch (Exception e) {
        logger.warn("failed to locate mail session : " + e);
        return;
    }
    Session session = (Session) factoryBean.getObject();
    sender = new JavaMailSenderImpl();
    sender.setSession(session);
    logger.info("email sender initialized from jndi name = '" + mailSessionJndiName + "'");
}

From source file:dk.nsi.haiba.lprimporter.config.LPRConfiguration.java

@Bean
public JavaMailSender javaMailSender() {
    Properties javaMailProperties = new Properties();
    javaMailProperties.put("mail.smtp.auth", smtpAuth);
    javaMailProperties.put("mail.smtp.starttls.enable", smtpStartTLS);
    javaMailProperties.put("mail.smtp.host", smtpHost);
    javaMailProperties.put("mail.smtp.port", smtpPort);

    JavaMailSenderImpl sender = new JavaMailSenderImpl();
    sender.setJavaMailProperties(javaMailProperties);
    if (smtpAuth) {
        sender.setUsername(smtpUser);//from  w  w w.  j  a  v a  2  s.c  o  m
        sender.setPassword(smtpPassword);
    }

    return sender;
}

From source file:info.jtrac.mail.MailSender.java

private void initMailSenderFromConfig(Map<String, String> config) {
    String host = config.get("mail.server.host");
    if (host == null) {
        logger.warn("'mail.server.host' config is null, mail sender not initialized");
        return;// ww  w .j  a v  a 2  s . c  om
    }
    String port = config.get("mail.server.port");
    String tempUrl = config.get("jtrac.url.base");
    from = config.get("mail.from");
    prefix = config.get("mail.subject.prefix");
    String userName = config.get("mail.server.username");
    String password = config.get("mail.server.password");
    String startTls = config.get("mail.server.starttls.enable");
    logger.info("initializing email adapter: host = '" + host + "', port = '" + port + "', url = '" + tempUrl
            + "', from = '" + from + "', prefix = '" + prefix + "'");
    this.prefix = prefix == null ? "[jtrac]" : prefix;
    this.from = from == null ? "jtrac" : from;
    this.url = tempUrl == null ? "http://localhost/jtrac/" : tempUrl;
    if (!this.url.endsWith("/")) {
        this.url = url + "/";
    }
    int p = 25;
    if (port != null) {
        try {
            p = Integer.parseInt(port);
        } catch (NumberFormatException e) {
            logger.warn("mail.server.port not an integer : '" + port + "', defaulting to 25");
        }
    }
    sender = new JavaMailSenderImpl();
    sender.setHost(host);
    sender.setPort(p);
    if (userName != null) {
        // authentication requested
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        if (startTls != null && startTls.toLowerCase().equals("true")) {
            props.put("mail.smtp.starttls.enable", "true");
        }
        sender.setJavaMailProperties(props);
        sender.setUsername(userName);
        sender.setPassword(password);
    }
    logger.info("email sender initialized from config: host = '" + host + "', port = '" + p + "'");
}

From source file:cn.org.once.cstack.initializer.CloudUnitApplicationContext.java

@Bean
@Conditional(value = EmailActiveCondition.class)
public JavaMailSender mailSender(@Value("${email.host}") String host, @Value("${email.port}") Integer port,
        @Value("${email.protocol}") String protocol, @Value("${email.username}") String username,
        @Value("${email.password}") String password) throws IOException {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(host);/*from  w w  w  .j  av  a2 s.  c  o m*/
    mailSender.setPort(port);
    mailSender.setProtocol(protocol);
    mailSender.setUsername(username);
    mailSender.setPassword(password);
    mailSender.setJavaMailProperties(javaMailProperties());
    return mailSender;
}

From source file:MailSender.java

private void initMailSenderFromJndi(String mailSessionJndiName) {
    logger.info("attempting to initialize mail sender from jndi name = '" + mailSessionJndiName + "'");
    JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
    factoryBean.setJndiName(mailSessionJndiName);
    // "java:comp/env/" will be prefixed if the JNDI name doesn't already
    // have it/*  ww w . j  a  v a 2 s. c o m*/

    // major: the above behavoiur is already documented
    // in the class JndiObjectFactoryBean. Remove it.

    factoryBean.setResourceRef(true);
    try {
        // this step actually does the JNDI lookup
        factoryBean.afterPropertiesSet();
    } catch (Exception e) {
        logger.warn("failed to locate mail session : " + e);
        return;
    }
    Session session = (Session) factoryBean.getObject();
    sender = new JavaMailSenderImpl();
    sender.setSession(session);
    logger.info("email sender initialized from jndi name = '" + mailSessionJndiName + "'");
}

From source file:MailSender.java

private void initMailSenderFromConfig(Map<String, String> config) {
    String host = config.get("mail.server.host");
    if (host == null) {
        logger.warn("'mail.server.host' config is null, mail sender not initialized");
        return;/*  w  ww. j  ava  2  s  .com*/
    }
    String port = config.get("mail.server.port");
    String localhost = config.get("mail.smtp.localhost");
    from = config.get("mail.from");
    prefix = config.get("mail.subject.prefix");
    String userName = config.get("mail.server.username");
    String password = config.get("mail.server.password");
    String startTls = config.get("mail.server.starttls.enable");
    logger.info("initializing email adapter: host = '" + host + "', port = '" + port + "', from = '" + from
            + "', prefix = '" + prefix + "'");
    this.prefix = prefix == null ? "[jtrac]" : prefix;
    this.from = from == null ? "jtrac" : from;
    int p = 25;
    if (port != null) {
        try {
            p = Integer.parseInt(port);
        } catch (NumberFormatException e) {
            logger.warn("mail.server.port not an integer : '" + port + "', defaulting to 25");
        }
    }
    sender = new JavaMailSenderImpl();
    sender.setHost(host);
    sender.setPort(p);
    Properties props = null;

    if (userName != null) {
        // authentication requested
        props = new Properties();
        props.put("mail.smtp.auth", "true");
        if (startTls != null && startTls.toLowerCase().equals("true")) {
            props.put("mail.smtp.starttls.enable", "true");
        }
        sender.setUsername(userName);
        sender.setPassword(password);
    }

    if (localhost != null) {
        if (props == null) {
            props = new Properties();
        }
        props.put("mail.smtp.localhost", localhost);
    }

    if (props != null) {
        sender.setJavaMailProperties(props);
    }

    logger.info("email sender initialized from config: host = '" + host + "', port = '" + p + "'");
}

From source file:gr.abiss.calipso.mail.MailSender.java

private void initMailSenderFromJndi(String mailSessionJndiName) {
    //logger.info("attempting to initialize mail sender from jndi name = '" + mailSessionJndiName + "'");
    JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
    factoryBean.setJndiName(mailSessionJndiName);
    // "java:comp/env/" will be prefixed if the JNDI name doesn't already have it
    factoryBean.setResourceRef(true);/* w w w  . j a  v a 2 s. c om*/
    try {
        // this step actually does the JNDI lookup
        factoryBean.afterPropertiesSet();
    } catch (Exception e) {
        logger.warn("failed to locate mail session : " + e);
        return;
    }
    Session session = (Session) factoryBean.getObject();
    sender = new JavaMailSenderImpl();
    sender.setSession(session);
    logger.info("email sender initialized from jndi name = '" + mailSessionJndiName + "'");
}