Search in sources :

Example 26 with JavaMailSenderImpl

use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-cloud-connectors by spring-cloud.

the class SmtpServiceConnectorCreatorTest method assertConnectorProperties.

private void assertConnectorProperties(SmtpServiceInfo serviceInfo, MailSender connector) {
    assertNotNull(connector);
    JavaMailSenderImpl javaMailSender = (JavaMailSenderImpl) connector;
    assertEquals(serviceInfo.getHost(), javaMailSender.getHost());
    assertEquals(serviceInfo.getPort(), javaMailSender.getPort());
    assertEquals(serviceInfo.getUserName(), javaMailSender.getUsername());
    assertEquals(serviceInfo.getPassword(), javaMailSender.getPassword());
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl)

Example 27 with JavaMailSenderImpl

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

the class MailSenderAutoConfigurationTests method mailSenderBackOff.

@Test
public void mailSenderBackOff() {
    load(ManualMailConfiguration.class, "spring.mail.host:smtp.acme.org", "spring.mail.user:user", "spring.mail.password:secret");
    JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context.getBean(JavaMailSender.class);
    assertThat(bean.getUsername()).isNull();
    assertThat(bean.getPassword()).isNull();
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) Test(org.junit.Test)

Example 28 with JavaMailSenderImpl

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

the class MailSenderAutoConfigurationTests method connectionOnStartup.

@Test
public void connectionOnStartup() throws MessagingException {
    load(MockMailConfiguration.class, "spring.mail.host:10.0.0.23", "spring.mail.test-connection:true");
    JavaMailSenderImpl mailSender = this.context.getBean(JavaMailSenderImpl.class);
    verify(mailSender, times(1)).testConnection();
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Test(org.junit.Test)

Example 29 with JavaMailSenderImpl

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

the class MailSenderAutoConfigurationTests method smtpHostSet.

@Test
public void smtpHostSet() {
    String host = "192.168.1.234";
    load(EmptyConfig.class, "spring.mail.host:" + host);
    JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context.getBean(JavaMailSender.class);
    assertThat(bean.getHost()).isEqualTo(host);
    assertThat(bean.getPort()).isEqualTo(JavaMailSenderImpl.DEFAULT_PORT);
    assertThat(bean.getProtocol()).isEqualTo(JavaMailSenderImpl.DEFAULT_PROTOCOL);
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) Test(org.junit.Test)

Example 30 with JavaMailSenderImpl

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

the class MailSenderAutoConfigurationTests method smtpHostWithSettings.

@Test
public void smtpHostWithSettings() {
    String host = "192.168.1.234";
    load(EmptyConfig.class, "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");
    JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context.getBean(JavaMailSender.class);
    assertThat(bean.getHost()).isEqualTo(host);
    assertThat(bean.getPort()).isEqualTo(42);
    assertThat(bean.getUsername()).isEqualTo("john");
    assertThat(bean.getPassword()).isEqualTo("secret");
    assertThat(bean.getDefaultEncoding()).isEqualTo("US-ASCII");
    assertThat(bean.getProtocol()).isEqualTo("smtps");
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) Test(org.junit.Test)

Aggregations

JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)56 Properties (java.util.Properties)25 Bean (org.springframework.context.annotation.Bean)14 MimeMessage (javax.mail.internet.MimeMessage)11 MessagingException (javax.mail.MessagingException)10 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)10 Test (org.junit.Test)9 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)6 Date (java.util.Date)4 IOException (java.io.IOException)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 MailException (org.springframework.mail.MailException)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