Search in sources :

Example 61 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project oc-explorer by devgateway.

the class EmailServiceConfiguration method javaMailSenderImpl.

@Bean
public JavaMailSenderImpl javaMailSenderImpl() {
    JavaMailSenderImpl jmsi = new JavaMailSenderImpl();
    jmsi.setHost("localhost");
    jmsi.setPort(SMTP_PORT);
    return jmsi;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Bean(org.springframework.context.annotation.Bean)

Example 62 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project alf.io by alfio-event.

the class SmtpMailer method toMailSender.

private static JavaMailSender toMailSender(Map<ConfigurationKeys, ConfigurationManager.MaybeConfiguration> conf) {
    JavaMailSenderImpl r = new CustomJavaMailSenderImpl();
    r.setDefaultEncoding("UTF-8");
    r.setHost(conf.get(SMTP_HOST).getRequiredValue());
    r.setPort(Integer.parseInt(conf.get(SMTP_PORT).getRequiredValue()));
    r.setProtocol(conf.get(SMTP_PROTOCOL).getRequiredValue());
    r.setUsername(conf.get(SMTP_USERNAME).getValueOrNull());
    r.setPassword(conf.get(SMTP_PASSWORD).getValueOrNull());
    String properties = conf.get(SMTP_PROPERTIES).getValueOrNull();
    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;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) ByteArrayResource(org.springframework.core.io.ByteArrayResource) IOException(java.io.IOException) EncodedResource(org.springframework.core.io.support.EncodedResource)

Aggregations

JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)62 Properties (java.util.Properties)25 Bean (org.springframework.context.annotation.Bean)16 MimeMessage (javax.mail.internet.MimeMessage)11 MessagingException (javax.mail.MessagingException)10 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)10 Test (org.junit.jupiter.api.Test)8 IOException (java.io.IOException)4 Date (java.util.Date)4 ByteArrayResource (org.springframework.core.io.ByteArrayResource)4 Test (org.junit.Test)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)3 GreenMail (com.icegreen.greenmail.util.GreenMail)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2