Search in sources :

Example 51 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project goci by EBISPOT.

the class GOCIMailConfiguration method javaMailSender.

// @Emma Code based on: http://stackoverflow.com/questions/22483407/send-emails-with-spring-by-using-java-annotations
@Bean
public JavaMailSender javaMailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setJavaMailProperties(getMailProperties());
    mailSender.setHost(host);
    mailSender.setPort(port);
    mailSender.setProtocol(protocol);
    return mailSender;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Bean(org.springframework.context.annotation.Bean)

Example 52 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.

the class MailSenderAutoConfigurationTests method smtpHostWithSettings.

@Test
void smtpHostWithSettings() {
    String host = "192.168.1.234";
    this.contextRunner.withPropertyValues("spring.mail.host:" + host, "spring.mail.port:42", "spring.mail.username:john", "spring.mail.password:secret", "spring.mail.default-encoding:US-ASCII", "spring.mail.protocol:smtps").run((context) -> {
        assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
        JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
        assertThat(mailSender.getHost()).isEqualTo(host);
        assertThat(mailSender.getPort()).isEqualTo(42);
        assertThat(mailSender.getUsername()).isEqualTo("john");
        assertThat(mailSender.getPassword()).isEqualTo("secret");
        assertThat(mailSender.getDefaultEncoding()).isEqualTo("US-ASCII");
        assertThat(mailSender.getProtocol()).isEqualTo("smtps");
    });
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Test(org.junit.jupiter.api.Test)

Example 53 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.

the class MailSenderAutoConfigurationTests method connectionOnStartup.

@Test
void connectionOnStartup() {
    this.contextRunner.withUserConfiguration(MockMailConfiguration.class).withPropertyValues("spring.mail.host:10.0.0.23", "spring.mail.test-connection:true").run((context) -> {
        assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
        JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
        then(mailSender).should().testConnection();
    });
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Test(org.junit.jupiter.api.Test)

Example 54 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.

the class MailSenderAutoConfigurationTests method mailSenderBackOff.

@Test
void mailSenderBackOff() {
    this.contextRunner.withUserConfiguration(ManualMailConfiguration.class).withPropertyValues("spring.mail.host:smtp.acme.org", "spring.mail.user:user", "spring.mail.password:secret").run((context) -> {
        assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
        JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
        assertThat(mailSender.getUsername()).isNull();
        assertThat(mailSender.getPassword()).isNull();
    });
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Test(org.junit.jupiter.api.Test)

Example 55 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.

the class MailSenderAutoConfigurationTests method smtpHostSet.

@Test
void smtpHostSet() {
    String host = "192.168.1.234";
    this.contextRunner.withPropertyValues("spring.mail.host:" + host).run((context) -> {
        assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
        JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
        assertThat(mailSender.getHost()).isEqualTo(host);
        assertThat(mailSender.getPort()).isEqualTo(JavaMailSenderImpl.DEFAULT_PORT);
        assertThat(mailSender.getProtocol()).isEqualTo(JavaMailSenderImpl.DEFAULT_PROTOCOL);
    });
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Test(org.junit.jupiter.api.Test)

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