Search in sources :

Example 1 with MessageService

use of org.apache.sling.commons.messaging.MessageService in project sling by apache.

the class SimpleMailServiceIT method sendWithoutAuthentication.

@Test
public void sendWithoutAuthentication() throws Exception {
    final Dictionary<String, Object> properties = MailBuilderConfigurations.minimal();
    createFactoryConfiguration(FACTORY_PID, properties);
    final MessageService messageService = getService(MessageService.class);
    final CompletableFuture<Result> future = messageService.send("simple test message", "recipient@example.net");
    try {
        future.get();
    } catch (Exception e) {
        logger.info(e.getMessage(), e);
        assertTrue(ExceptionUtils.getRootCause(e) instanceof AuthenticationFailedException);
    }
}
Also used : AuthenticationFailedException(javax.mail.AuthenticationFailedException) MessageService(org.apache.sling.commons.messaging.MessageService) AuthenticationFailedException(javax.mail.AuthenticationFailedException) Result(org.apache.sling.commons.messaging.Result) MailResult(org.apache.sling.commons.messaging.mail.MailResult) Test(org.junit.Test)

Example 2 with MessageService

use of org.apache.sling.commons.messaging.MessageService in project sling by apache.

the class SimpleMailServiceIT method send.

@Test
public void send() throws Exception {
    final Dictionary<String, Object> properties = MailBuilderConfigurations.full(wiser.getServer().getPort());
    createFactoryConfiguration(FACTORY_PID, properties);
    final MessageService messageService = getService(MessageService.class);
    final CompletableFuture<Result> future = messageService.send("simple test message", "recipient@example.net");
    final MailResult result = (MailResult) future.get();
    final String message = new String(result.getMessage(), StandardCharsets.UTF_8);
    // TODO assert
    logger.info("message: {}", message);
}
Also used : MailResult(org.apache.sling.commons.messaging.mail.MailResult) MessageService(org.apache.sling.commons.messaging.MessageService) Result(org.apache.sling.commons.messaging.Result) MailResult(org.apache.sling.commons.messaging.mail.MailResult) Test(org.junit.Test)

Example 3 with MessageService

use of org.apache.sling.commons.messaging.MessageService in project sling by apache.

the class SimpleMailServiceIT method sendWithData.

@Test
public void sendWithData() throws Exception {
    final Dictionary<String, Object> properties = MailBuilderConfigurations.full(wiser.getServer().getPort());
    createFactoryConfiguration(FACTORY_PID, properties);
    final MessageService messageService = getService(MessageService.class);
    final Map configuration = Collections.singletonMap("mail.subject", "Testing the Simple Mail Service with a custom subject");
    final Map data = Collections.singletonMap("mail", configuration);
    final CompletableFuture<Result> future = messageService.send("simple test message", "recipient@example.net", data);
    final MailResult result = (MailResult) future.get();
    final String message = new String(result.getMessage(), StandardCharsets.UTF_8);
    // TODO assert
    logger.info("message: {}", message);
}
Also used : MailResult(org.apache.sling.commons.messaging.mail.MailResult) Map(java.util.Map) MessageService(org.apache.sling.commons.messaging.MessageService) Result(org.apache.sling.commons.messaging.Result) MailResult(org.apache.sling.commons.messaging.mail.MailResult) Test(org.junit.Test)

Aggregations

MessageService (org.apache.sling.commons.messaging.MessageService)3 Result (org.apache.sling.commons.messaging.Result)3 MailResult (org.apache.sling.commons.messaging.mail.MailResult)3 Test (org.junit.Test)3 Map (java.util.Map)1 AuthenticationFailedException (javax.mail.AuthenticationFailedException)1