use of io.quarkus.mailer.Mail in project kogito-runtimes by kiegroup.
the class QuarkusMailSender method onDeadline.
@Incoming("kogito-deadline-consumer")
public void onDeadline(UserTaskDeadlineDataEvent event) {
MailInfo mailInfo = MailInfo.of(event.getData());
logger.info("Sending e-mail {}", mailInfo);
Mail message = new Mail();
if (mailInfo.to() != null) {
message.setTo(Arrays.asList(mailInfo.to()));
}
if (mailInfo.from() != null) {
message.setFrom(mailInfo.from());
}
if (mailInfo.replyTo() != null) {
message.setReplyTo(mailInfo.replyTo());
}
if (mailInfo.subject() != null) {
message.setSubject(mailInfo.subject());
}
if (mailInfo.body() != null) {
message.setText(mailInfo.body());
}
mailer.send(message).subscribe().with(this::handleCompleted, this::handleFailure);
}
use of io.quarkus.mailer.Mail in project automatiko-engine by automatiko-io.
the class VerificationTest method testProcessExecutionV2.
@SuppressWarnings("unchecked")
@Test
public void testProcessExecutionV2() {
String key = "test";
String addPayload = "{\n" + " \"email\": \"john@email.com\",\n" + " \"person\": {\n" + " \"adult\": true,\n" + " \"age\": 30,\n" + " \"name\": \"john\"\n" + " },\n" + " \"resume\": {\n" + " \"attributes\": {\n" + " },\n" + " \"content\": \"aGVsbG8=\",\n" + " \"name\": \"test.txt\"\n" + " },\n" + " \"coverLetter\": {\n" + " \"attributes\": {\n" + " },\n" + " \"content\": \"aGVsbG8=\",\n" + " \"name\": \"cover-letter.pdf\"\n" + " }\n" + "}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/notifications?businessKey=" + key).then().statusCode(200).body("id", equalTo("test"), "extracted", nullValue());
List<Mail> sent = mailbox.getMessagesSentTo("john@email.com");
assertEquals(1, sent.size());
Mail actual = sent.get(0);
assertTrue(actual.getHtml().contains("<h1>Hello john</h1>"));
assertEquals("Notification", actual.getSubject());
assertEquals(1, actual.getAttachments().size());
assertEquals("application/zip", actual.getAttachments().get(0).getContentType());
assertEquals("documents.zip", actual.getAttachments().get(0).getName());
given().accept(ContentType.JSON).when().get("/notifications").then().statusCode(200).body("$.size()", is(1));
List<Map<String, String>> taskInfo = given().accept(ContentType.JSON).when().get("/notifications/" + key + "/tasks").then().statusCode(200).extract().as(List.class);
assertEquals(1, taskInfo.size());
String taskId = taskInfo.get(0).get("id");
String taskName = taskInfo.get(0).get("name");
assertEquals("validate", taskName);
String payload = "{}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(payload).when().post("/notifications/" + key + "/" + taskName + "/" + taskId).then().statusCode(200).body("id", is(key), "extracted", notNullValue());
given().accept(ContentType.JSON).when().get("/notifications").then().statusCode(200).body("$.size()", is(0));
}
use of io.quarkus.mailer.Mail in project automatiko-engine by automatiko-io.
the class SendEmailService method sendSimpleCorrelatedWithCC.
/**
* Sends email to the given list of recipients and cc recipients with given subject and body.
* Optionally given attachments will be put on the message as well
*
* In case of error a <code>ServiceExecutionError</code> will be thrown with error code set to <code>sendEmailFailure</code>
* so it can be used within workflow definition to handle it
*
* @param correlation correlation information to be attached to the message
* @param tosc comma separated list of recipients
* @param ccs comma separated list of CC recipients
* @param subject subject of the email
* @param body body of the email
* @param attachments optional attachments
*/
public void sendSimpleCorrelatedWithCC(String correlation, String tos, String ccs, String subject, String body, File<byte[]>... attachments) {
try {
for (String to : tos.split(",")) {
Mail mail = Mail.withHtml(to, subject, body);
for (String cc : ccs.split(",")) {
mail.addCc(cc);
}
for (File<byte[]> attachment : attachments) {
if (attachment == null) {
continue;
}
mail.addAttachment(attachment.name(), attachment.content(), attachment.type());
}
mail.addHeader("Message-ID", EmailUtils.messageIdWithCorrelation(correlation, host.orElse("localhost")));
mailer.send(mail);
}
} catch (Exception e) {
throw new ServiceExecutionError("sendEmailFailure", e.getMessage(), e);
}
}
use of io.quarkus.mailer.Mail in project automatiko-engine by automatiko-io.
the class SendEmailService method sendSimpleWithCC.
/**
* Sends email to the given list of recipients and cc recipients with given subject and body.
* Optionally given attachments will be put on the message as well
*
* In case of error a <code>ServiceExecutionError</code> will be thrown with error code set to <code>sendEmailFailure</code>
* so it can be used within workflow definition to handle it
*
* @param tosc comma separated list of recipients
* @param ccs comma separated list of CC recipients
* @param subject subject of the email
* @param body body of the email
* @param attachments optional attachments
*/
public void sendSimpleWithCC(String tos, String ccs, String subject, String body, File<byte[]>... attachments) {
try {
for (String to : tos.split(",")) {
Mail mail = Mail.withHtml(to, subject, body);
for (String cc : ccs.split(",")) {
mail.addCc(cc);
}
for (File<byte[]> attachment : attachments) {
if (attachment == null) {
continue;
}
mail.addAttachment(attachment.name(), attachment.content(), attachment.type());
}
mailer.send(mail);
}
} catch (Exception e) {
throw new ServiceExecutionError("sendEmailFailure", e.getMessage(), e);
}
}
use of io.quarkus.mailer.Mail in project automatiko-engine by automatiko-io.
the class SendEmailService method sendWithBCC.
/**
* Sends email to the given list of recipients and cc recipients with given subject and body that is created based on the
* given template.
* Optionally given attachments will be put on the message as well
*
* In case of error a <code>ServiceExecutionError</code> will be thrown with error code set to <code>sendEmailFailure</code>
* so it can be used within workflow definition to handle it
*
* In case template cannot be found with given name a <code>ServiceExecutionError</code> will
* be thrown with error code set to <code>emailTemplateNotFound</code>
*
* @param tos comma separated list of recipients
* @param bccs comma separated list of BCC recipients
* @param subject subject of the email
* @param templateName name of the email template to be used to create the body of the email message
* @param body body of the email
* @param attachments optional attachments
*/
public void sendWithBCC(String tos, String bccs, String subject, String templateName, Object body, File<byte[]>... attachments) {
Template template = getTemplate(templateName);
try {
Map<String, Object> templateData = new HashMap<>();
templateData.put("body", body);
String content = template.instance().data(templateData).render();
for (String to : tos.split(",")) {
Mail mail = Mail.withHtml(to, subject, content);
for (String bcc : bccs.split(",")) {
mail.addBcc(bcc);
}
for (File<byte[]> attachment : attachments) {
if (attachment == null) {
continue;
}
mail.addAttachment(attachment.name(), attachment.content(), attachment.type());
}
mailer.send(mail);
}
} catch (Exception e) {
throw new ServiceExecutionError("sendEmailFailure", e.getMessage(), e);
}
}
Aggregations