Send Email

Send Email addon service comes with support for sending emails. It provides io.automatiko.engine.addons.services.email.SendEmailService that comes with following operations

  • sendSimple* with given body

  • send* with template based body

A complete set of methods available in this service

Method name Description Parameters

sendSimple

Allows to send simple body email - given as parameter to main recipients only (one or more)

  • String tos

  • String subject

  • String body

  • File<byte[]>…​ attachments

sendSimpleWithCC

Allows to send simple body email - given as parameter to main recipients and CC recipients (one or more)

  • String tos

  • String ccs

  • String subject

  • String body

  • File<byte[]>…​ attachments

sendSimpleWithBCC

Allows to send simple body email - given as parameter to main recipients and BCC recipients (one or more)

  • String tos

  • String bccs

  • String subject

  • String body

  • File<byte[]>…​ attachments

sendSimpleCorrelated

Allows to send simple body email - given as parameter to main recipients only (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String subject

  • String body

  • File<byte[]>…​ attachments

sendSimpleCorrelatedWithCC

Allows to send simple body email - given as parameter to main recipients and CC recipients (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String ccs

  • String subject

  • String body

  • File<byte[]>…​ attachments

sendSimpleCorrelatedWithBCC

Allows to send simple body email - given as parameter to main recipients and BCC recipients (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String bccs

  • String subject

  • String body

  • File<byte[]>…​ attachments

send

Allows to send generated body (based on template and data) email to main recipients only (one or more)

  • String tos

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

sendWithCC

Allows to send generated body (based on template and data) email to main recipients and CC recipients (one or more)

  • String tos

  • String ccs

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

sendWithBCC

Allows to send generated body (based on template and data) email to main recipients and BCC recipients (one or more)

  • String tos

  • String bccs

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

sendCorrelated

Allows to send generated body (based on template and data) email to main recipients only (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

sendCorrelatedWithCC

Allows to send generated body (based on template and data) email to main recipients and CC recipients (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String ccs

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

sendCorrelatedWithBCC

Allows to send generated body (based on template and data) email to main recipients and BCC recipients (one or more) with correlation information of the workflow instance

  • String correlation

  • String tos

  • String bccs

  • String subject

  • String template

  • Object data

  • File<byte[]>…​ attachments

When using correlated email send operations to pass in the correlation you can use #{processInstanceId} expression in the data mapping. You can also use values that match any of the tags of the workflow instance.
Regardless of the operation type, recipients (both TO and CC or BCC) can be given as list of comma separated addresses e.g. john@email.com,mary@email.com

Send with given body operation

Send email with given body is based on complete body to be given to the operation and thus it will not perform any modification to it.

There are two flavors of the operation that differs in the set of recipients - sending only to main recipients (TO) - sending to both main recipients and CC recipients - sending to both main recipients and BCC recipients

Data mapping

When used via service task this service expects following data mapping

  • Inputs

    • to - one or more email addresses of recipients

    • cc - one or more CC email recipients - this can be completely omitted

    • subject - subject of the email message

    • body - complete body of the email message

Optionally as last inputs attachments can be given. There maybe 0 or more attachments and they should be of type io.automatiko.engine.api.workflow.files.File

There are no outputs to be defined.

On success

Successful operation will not produce any results

On failure

Failure during creation of the archive will throw a io.automatiko.engine.api.workflow.ServiceExecutionError with error code sendEmailFailure so it can be used within workflow definition to handle errors

Send with template based body operation

Send email with template based body is based on generating email body based on given template (identified by name) and the context object. Both must be given to properly produce and send email.

There are two flavors of the operation that differs in the set of recipients - sending only to main recipients (TO) - sending to both main recipients and CC recipients - sending to both main recipients and BCC recipients

When creating templates (usually html files) to refer to context object use body variable. Following examples shows how to access name of the person that is given as context object:

<html>
  <body>

	<h1>Hello {body.name}</h1>

	<p>Here is a bit of information for you!</p>
  </body>
</html>

All templates must be stored in templates folder under src/main/resources of your project.

Data mapping

When used via service task this service expects following data mapping

  • Inputs

    • to - one or more email addresses of recipients

    • cc - one or more CC email recipients - this can be completely omitted

    • subject - subject of the email message

    • template - name of the template to be used to generate email body

    • body - a context object that will be given as body into the template generation

Optionally as last inputs attachments can be given. There maybe 0 or more attachments and they should be of type io.automatiko.engine.api.workflow.files.File

There are no outputs to be defined.

On success

Successful operation will not produce any results.

On failure

Failure during creation of the archive will throw a io.automatiko.engine.api.workflow.ServiceExecutionError with error code

  • sendEmailFailure

  • emailTemplateNotFound

so it can be used within workflow definition to handle errors

Usage

To be able to use this service addon a project must be given following dependency

<dependency>
  <groupId>io.automatiko.addons.services</groupId>
  <artifactId>automatiko-send-email-addon</artifactId>
</dependency>

There is a need to provide email server configuration via application.properties file

quarkus.mailer.auth-methods=DIGEST-MD5 CRAM-SHA256 CRAM-SHA1 CRAM-MD5 PLAIN LOGIN
quarkus.mailer.from=YOUR_EMAIL@gmail.com
quarkus.mailer.host=smtp.gmail.com
quarkus.mailer.port=587
quarkus.mailer.start-tls=REQUIRED
quarkus.mailer.username=YOUR_EMAIL@gmail.com
quarkus.mailer.password=PASSWORD

Declare service interface

declare interface

Configure service task interface

email 1

Configure parameters to invoke (in this case the send operation with template names notifications)

email 2

In this example

  • email is sent to address taken from workflow instance variable called email

  • with subject set to Notifications

  • body is generated based on template named notifications and the person workflow instance variable is given as context to template generation

  • documents workflow instance variable is used as attachment to the email (in this case a zip file)