use of org.apache.sling.commons.messaging.mail.MailResult 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);
}
use of org.apache.sling.commons.messaging.mail.MailResult 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);
}
use of org.apache.sling.commons.messaging.mail.MailResult in project sling by apache.
the class SimpleMailService method sendMail.
private MailResult sendMail(final String message, final String recipient, final Map data, final MailBuilder mailBuilder) {
try {
final Email email = mailBuilder.build(message, recipient, data);
final String messageId = email.send();
logger.info("mail '{}' sent", messageId);
final byte[] bytes = MailUtil.toByteArray(email);
return new MailResult(bytes);
} catch (EmailException | MessagingException | IOException e) {
throw new CompletionException(e);
}
}
Aggregations