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

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

Introduction

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

Prototype

public void setDefaultEncoding(@Nullable String defaultEncoding) 

Source Link

Document

Set the default encoding to use for MimeMessage MimeMessages created by this instance.

Usage

From source file:org.davidmendoza.demo.config.MailConfig.java

@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(mailHost);/*  www.j  a  va2 s.c o  m*/
    mailSender.setPort(new Integer(mailPort));
    return mailSender;
}

From source file:com.springsource.greenhouse.config.MailConfig.java

/**
 * The Java Mail sender./*  ww w  .  jav a  2  s  .c  o  m*/
 * It's not generally expected for mail sending to work in embedded mode.
 * Since this mail sender is always invoked asynchronously, this won't cause problems for the developer.
 */
@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(environment.getProperty("mail.host"));
    mailSender.setPort(environment.getProperty("mail.port", Integer.class, 25));
    mailSender.setUsername(environment.getProperty("mail.username"));
    mailSender.setPassword(environment.getProperty("mail.password"));
    Properties properties = new Properties();
    properties.put("mail.smtp.auth", environment.getProperty("mail.smtp.auth", Boolean.class, false));
    properties.put("mail.smtp.starttls.enable",
            environment.getProperty("mail.smtp.starttls.enable", Boolean.class, false));
    mailSender.setJavaMailProperties(properties);
    return mailSender;
}

From source file:org.davidmendoza.fileUpload.config.MailConfig.java

@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(mailHost);/*from www. j  av  a 2  s  .c o  m*/
    mailSender.setPassword(mailPassword);
    mailSender.setUsername(mailUser);
    mailSender.setPort(new Integer(mailPort));
    Properties properties = new Properties();
    properties.put("mail.smtp.auth", mailAuth);
    properties.put("mail.smtp.starttls.enable", mailStarttls);
    properties.put("mail.smtp.socketFactory.class", mailSocketFactory);
    properties.put("mail.debug", mailDebug);
    mailSender.setJavaMailProperties(properties);
    return mailSender;
}

From source file:com.github.javarch.support.config.EMailConfig.java

/**
 * http://support.google.com/mail/bin/answer.py?hl=en&answer=13287
 * @return//from w  ww  .j a  v a 2  s  .c om
 */
@Bean
public MailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(env.getRequiredProperty("mail.host"));
    mailSender.setPassword(env.getRequiredProperty("mail.password"));
    mailSender.setUsername(env.getRequiredProperty("mail.username"));
    mailSender.setPort(env.getProperty("mail.port", Integer.class, 25));
    mailSender.setProtocol(env.getRequiredProperty("mail.transport.protocol"));

    mailSender.setJavaMailProperties(mailProperties());

    return mailSender;
}

From source file:io.lavagna.model.MailConfig.java

private JavaMailSender toMailSender() {
    JavaMailSenderImpl r = new JavaMailSenderImpl();
    r.setDefaultEncoding("UTF-8");
    r.setHost(host);// ww  w  .  j a v  a2 s. c o  m
    r.setPort(port);
    r.setProtocol(protocol);
    r.setUsername(username);
    r.setPassword(password);
    if (properties != null) {
        try {
            Properties prop = PropertiesLoaderUtils.loadProperties(
                    new EncodedResource(new ByteArrayResource(properties.getBytes("UTF-8")), "UTF-8"));
            r.setJavaMailProperties(prop);
        } catch (IOException e) {
            LOG.warn("error while setting the mail sender properties", e);
        }
    }
    return r;
}

From source file:br.eti.danielcamargo.backend.common.config.context.CoreConfig.java

@Bean(name = "mailSender")
public JavaMailSender mailSender() throws PropertyVetoException {
    JavaMailSenderImpl bean = new JavaMailSenderImpl();
    bean.setDefaultEncoding("UTF-8");
    bean.setHost("smtp.gmail.com");
    bean.setPort(587);/*  w  w  w  .j  a  v  a  2 s .  c o m*/
    bean.setUsername("danielsudpr@gmail.com ");
    bean.setPassword("***");

    Properties properties = new Properties();
    properties.put("mail.smtp.auth", true);
    properties.put("mail.smtp.starttls.enable", true);

    bean.setJavaMailProperties(properties);

    return bean;
}

From source file:org.craftercms.social.services.system.EmailService.java

private JavaMailSender loadConfig(final String cacheKey, final Map<String, Object> emailPreferences)
        throws SocialException {
    if (emailPreferences != null) {
        JavaMailSenderImpl toReturn = new JavaMailSenderImpl();
        toReturn.setDefaultEncoding(emailPreferences.get("encoding").toString());

        toReturn.setHost(emailPreferences.get("host").toString());
        toReturn.setPort(NumberUtils.toInt(emailPreferences.get("port").toString(), 25));
        final Properties javaMailProps = new Properties();
        if (Boolean.parseBoolean(emailPreferences.get("auth").toString())) {
            toReturn.setUsername(emailPreferences.get("username").toString());
            toReturn.setPassword(emailPreferences.get("password").toString());
            javaMailProps.put("mail.smtp.auth", "true");
        }/*www .  ja  v  a  2s .  co  m*/
        if (Boolean.parseBoolean(emailPreferences.get("tls").toString())) {
            javaMailProps.put("mail.smtp.starttls.enable", "true");
        }
        toReturn.setJavaMailProperties(javaMailProps);
        emailConfigCache.put(new Element(cacheKey, toReturn));
        return toReturn;
    } else {
        throw new SocialException("Email is not configure for context " + cacheKey);
    }
}

From source file:alfio.manager.system.SmtpMailer.java

private JavaMailSender toMailSender(Event event) {
    JavaMailSenderImpl r = new CustomJavaMailSenderImpl();
    r.setDefaultEncoding("UTF-8");

    r.setHost(configurationManager/*from   w w w . j a  v  a 2  s. co m*/
            .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_HOST)));
    r.setPort(Integer.valueOf(configurationManager
            .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PORT))));
    r.setProtocol(configurationManager
            .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROTOCOL)));
    r.setUsername(configurationManager.getStringConfigValue(
            Configuration.from(event.getOrganizationId(), event.getId(), SMTP_USERNAME), null));
    r.setPassword(configurationManager.getStringConfigValue(
            Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PASSWORD), null));

    String properties = configurationManager.getStringConfigValue(
            Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROPERTIES), null);

    if (properties != null) {
        try {
            Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource(
                    new ByteArrayResource(properties.getBytes(StandardCharsets.UTF_8)), "UTF-8"));
            r.setJavaMailProperties(prop);
        } catch (IOException e) {
            log.warn("error while setting the mail sender properties", e);
        }
    }
    return r;
}

From source file:org.smigo.config.ProductionConfiguration.java

@Bean
public JavaMailSenderImpl javaMailSender() {
    log.debug("JavaMailSender init");
    final JavaMailSenderImpl ret = new JavaMailSenderImpl();
    ret.setUsername(mailSenderUsername);
    ret.setPassword(mailSenderPassword);
    ret.setHost(mailSenderHost);//from w ww . ja v a 2s  . c o m
    ret.setPort(mailSenderPort);
    ret.setDefaultEncoding("UTF-8");

    final Properties props = new Properties();
    props.setProperty("mail.smtp.starttls.enable", "true");
    props.setProperty("mail.smtp.auth", "true");
    props.setProperty("mail.smtp.ssl.enable", "true");
    props.setProperty("mail.smtp.ssl.trust", mailSenderHost);

    ret.setJavaMailProperties(props);
    return ret;
}

From source file:com.pamarin.income.component.MailSenderImpl.java

private JavaMailSender senderSetup() throws IOException {
    Properties config = loadMailConfig();
    Properties pro = propertiesSetup();
    String username = config.getProperty("email.username");
    String password = config.getProperty("email.password");

    if (username == null) {
        throw new UncheckedMailException("require property email.username on classpath:" + EMAIL_CONFIG);
    }/*from  w  ww .j a  v  a 2 s  .co m*/

    if (password == null) {
        throw new UncheckedMailException("require property email.password on classpath:" + EMAIL_CONFIG);
    }

    JavaMailSenderImpl sender = new JavaMailSenderImpl();
    sender.setJavaMailProperties(pro);
    sender.setUsername(username);
    sender.setPassword(password);
    sender.setProtocol("smtps");
    sender.setPort(465);
    sender.setHost(SMTP_HOST_NAME);
    sender.setDefaultEncoding("utf-8");

    return sender;
}