Search in sources :

Example 1 with MailSender

use of org.springframework.mail.MailSender in project spring-integration by spring-projects.

the class MailOutboundChannelAdapterParserTests method adapterWithJavaMailProperties.

@Test
public void adapterWithJavaMailProperties() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("MailOutboundWithJavamailProperties-context.xml", this.getClass());
    Object adapter = context.getBean("adapterWithHostProperty.adapter");
    MailSendingMessageHandler handler = (MailSendingMessageHandler) new DirectFieldAccessor(adapter).getPropertyValue("handler");
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
    MailSender mailSender = (MailSender) fieldAccessor.getPropertyValue("mailSender");
    assertNotNull(mailSender);
    Properties javaMailProperties = (Properties) TestUtils.getPropertyValue(mailSender, "javaMailProperties");
    assertEquals(7, javaMailProperties.size());
    assertNotNull(javaMailProperties);
    assertEquals("true", javaMailProperties.get("mail.smtps.auth"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MailSender(org.springframework.mail.MailSender) MailSendingMessageHandler(org.springframework.integration.mail.MailSendingMessageHandler) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with MailSender

use of org.springframework.mail.MailSender in project spring-integration by spring-projects.

the class MailOutboundChannelAdapterParserTests method adapterWithHostProperty.

@Test
public void adapterWithHostProperty() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("mailOutboundChannelAdapterParserTests.xml", this.getClass());
    Object adapter = context.getBean("adapterWithHostProperty.adapter");
    MailSendingMessageHandler handler = (MailSendingMessageHandler) new DirectFieldAccessor(adapter).getPropertyValue("handler");
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
    MailSender mailSender = (MailSender) fieldAccessor.getPropertyValue("mailSender");
    assertNotNull(mailSender);
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MailSender(org.springframework.mail.MailSender) MailSendingMessageHandler(org.springframework.integration.mail.MailSendingMessageHandler) Test(org.junit.Test)

Example 3 with MailSender

use of org.springframework.mail.MailSender in project spring-thymeleaf-simplefinance by heitkergm.

the class Application method sendStartupEmail.

private static void sendStartupEmail(final ApplicationContext ctx) {
    MailSender mailer = ctx.getBean(MailSender.class);
    SimpleMailMessage msg = new SimpleMailMessage();
    String envProp = System.getenv("MAIL_TO");
    String recipient;
    recipient = envProp != null ? envProp : ctx.getMessage("mail.to", new Object[] {}, Locale.getDefault());
    msg.setFrom(ctx.getMessage("mail.sender", new Object[] {}, Locale.getDefault()));
    msg.setTo(recipient);
    msg.setSubject(ctx.getMessage("mail.subject", new Object[] {}, Locale.getDefault()));
    msg.setText(ctx.getMessage("mail.upmsg", new Object[] {}, Locale.getDefault()));
    mailer.send(msg);
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailSender(org.springframework.mail.MailSender)

Example 4 with MailSender

use of org.springframework.mail.MailSender in project spring-integration by spring-projects.

the class MailOutboundChannelAdapterParserTests method adapterWithMailSenderReference.

@Test
public void adapterWithMailSenderReference() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("mailOutboundChannelAdapterParserTests.xml", this.getClass());
    Object adapter = context.getBean("adapterWithMailSenderReference.adapter");
    MailSendingMessageHandler handler = (MailSendingMessageHandler) new DirectFieldAccessor(adapter).getPropertyValue("handler");
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(handler);
    MailSender mailSender = (MailSender) fieldAccessor.getPropertyValue("mailSender");
    assertNotNull(mailSender);
    assertEquals(23, fieldAccessor.getPropertyValue("order"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MailSender(org.springframework.mail.MailSender) MailSendingMessageHandler(org.springframework.integration.mail.MailSendingMessageHandler) Test(org.junit.Test)

Example 5 with MailSender

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

the class SmtpServiceConnectorCreatorTest method cloudMailSenderCreation.

@Test
public void cloudMailSenderCreation() throws Exception {
    SmtpServiceInfo serviceInfo = createServiceInfo();
    MailSender dataSource = testCreator.create(serviceInfo, null);
    assertConnectorProperties(serviceInfo, dataSource);
}
Also used : SmtpServiceInfo(org.springframework.cloud.service.common.SmtpServiceInfo) MailSender(org.springframework.mail.MailSender) Test(org.junit.Test)

Aggregations

MailSender (org.springframework.mail.MailSender)5 Test (org.junit.Test)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 MailSendingMessageHandler (org.springframework.integration.mail.MailSendingMessageHandler)3 Properties (java.util.Properties)1 SmtpServiceInfo (org.springframework.cloud.service.common.SmtpServiceInfo)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1