Email

Overview

The EmailWorkEntryExecutor executable can send one or more emails from a Task.

This executable uses the Code Block to define the default message. The default message can contain Internal variables or HTML. If a different default message is specified in a Data Block of a Task, this message is displayed instead of the one specified in the Code Block.

Java properties

The ria-boot.properties file must be configured for the email server. All standard Java mail properties with the mail. format are supported, but they must be prefixed by com.ria. for the runtime server to accept them. For example:

com.ria.mail.debug = false
com.ria.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
com.ria.mail.smtp.host = smtp.gmail.com
com.ria.mail.smtp.port = 465
com.ria.mail.smtp.auth = true
com.ria.mail.user = email-user@gmail.com
com.ria.mail.password = SMTPPassword

The password property can be encrypted by running the encrypt utility and selecting #4.

Parameters

This executable class accepts the following parameters:

Parameter Description
from

Specifies the address sending the email. For example, noreply@email.com.

Mandatory: Yes

to

Specifies the recipients of the email.

If there are multiple recipients, separate the email addresses with a ,. For example, jane@email.com, joe@email.com.

cc

Specifies the CC recipients of the email.

If there are multiple recipients, separate the email addresses with a ,. For example, jane@email.com, joe@email.com.

bcc

Specifies the BCC recipients of the email.

If there are multiple recipients, separate the email addresses with a ,. For example, jane@email.com, joe@email.com.

subject Defines the email subject. It can include Internal variables, for example, Job {$jobName} Sequence {$runSeq}.
attachments

Lists all files to attach to the email. If multiple files need to be attached, separate each file with a ,.

A filename can include Internal variables, * and ? wildcard characters, or a combination of both. This allows you to select files for the current date or a specific run id.

ignoreFileNotFound

If set to true, the executable continues until completion, even if the specified attachment is not found.

This does not apply to wildcards. No attachments will be sent if a wildcard did not select any files.

Mandatory: No
Default: false

wildcardListCount

Specifies the maximum files a wildcard can select.

Mandatory: No

Default: -1 that selects all files satisfying the wildcard.

wildcardListOrder

Determines the order of the files for the wildcard to select.

Mandatory: No
Default: d
Set to s for ascending order.

message Not strictly a parameter, as the default message is specified in a Task. See Overview.
sourceId Defines a source query or table from which to select the data for sending multiple emails. An email is generated for each selected row.

Email Data Blocks

In the Data Blocks of a Task, you can specify email parameters for multiple emails. This allows you to send multiple emails in a single task. To send multiple emails in a single task, create a Data Block for each email with its parameters.

In the Data Blocks, parameters are specified in the following form:

parameterName = value

The parameterName must be one of the supported Parameters. The value can have multiple lines.

Without a Data Block, the Executable uses the parameter definitions for a single email or multiple emails if sourceId is specified.

Email Groovy integration

When dealing with dynamic emails, you can use a Groovy class or code snippets. Groovy runs within the JVM and is controlled by the DIH framework, so it can access the same classes, objects, and environmental components as DIH. This allows you to manipulate the file upload data while it is being uploaded, reducing the need for temporary or staging areas.

There is no parameter for Groovy. It should be coded in any of the following:

Email Groovy class and snippets

To add a Groovy class or snippet to an email Task, add the following:

groovy = <groovy code goes here>

The following is an example of a Groovy class:

groovy =
import com.xyz.ClassAbc
class MyEmailClass {
    def myInstanceVariable
    def buildSubject(columnValueMap) {
        return 'Subject from Groovy!'
    }
    def buildAttachments(columnValueMap) {
        return columnValueMap.get('MY_ATTACHMENTS')
    }
}

The following is an example of a Groovy snippet:

groovy =
    def buildSubject(columnValueMap) {
        return 'Subject from Groovy!'
    }
    def buildAttachments(columnValueMap) {
        return columnValueMap.get('MY_ATTACHMENTS')
    }

Email Groovy methods

The following methods can be implemented to format the various parts of an email. All methods are optional.

The methods described below all receive a columnValueMap parameter, which is a Java HashMap containing the columns and their respective values selected by the specified source. When a row is selected, the methods will be called and provided with the columnValueMap for that specific row. If no source is specified, the columnValueMap will be an empty map.

To extract a column value from the map, use the get method and always specify the column name in uppercase. For example:

def myFromAddress = columnValueMap.get('MY_FROM_ADDRESS')

If a method returns null, that component of the email will be taken from its associated parameter.

startEmail

The startEmail method performs the initial processing for an email.

def startEmail(String runDataPrimaryKey, int dataBlockSeq, Map<String, String> columnValueMap){
    return output
}

The runDataPrimaryKey is the primary key value from the source data. It contains the column values identified as the primary key. If it’s a composite key, the values will be concatenated with a ~ between them. If there is no specified source, the value of the runDataPrimaryKey is 1.

The dataBlockSeq is the sequence of the Task Data Block for the current email.

This method returns the following Boolean values:

  • true — Implemented Groovy email methods will be called, and the email will be sent.
  • false — Email will not be sent.

buildFrom

The buildFrom method specifies the email address of the sender.

def buildFrom(Map<String, String> columnValueMap){
    return output
}

This method returns a string, for example:

return 'do-not-reply@company.com'

buildTo

The buildFrom method specifies the email addresses of the recipients.

def buildFrom(Map<String, String> columnValueMap){
    return output
}

This method returns a comma-delimited list of strings, for example:

return 'recipient1@company.com,recipient2@company.com'

buildCc

The buildCc method specifies the email addresses of the carbon copy or CC recipients.

def buildCc(Map<String, String> columnValueMap){
    return output
}

This method returns a comma-delimited list of strings, for example:

return 'ccrecipient1@company.com,ccrecipient2@company.com'

buildBcc

The buildBcc method specifies the email addresses of the blind carbon copy or BCC recipients.

def buildBcc(Map<String, String> columnValueMap){
    return output
}

This method returns a comma-delimited list of strings, for example:

return 'blind-recipient1@company.com,blind-recipient2@company.com'

buildSubject

The buildSubject method specifies the subject of the email.

def buildSubject(Map<String, String> columnValueMap){
    return output
}

This method returns a string, for example:

return 'This is an email from Groovy'

buildAttachments

The buildAttachments method builds a list of file names to attach to the email.

def buildAttachments(Map<String, String> columnValueMap){
    return output
}

This method returns a comma-delimited list of full path names, for example:

return '/var/tmp/file1.txt,/var/tmp/file2.csv'

buildMessage

The buildMessage method builds a list of file names to attach to the email.

def buildMessage(Map<String, String> columnValueMap){
    return output
}

This method returns a comma-delimited list of full path names, for example:

return '/var/tmp/file1.txt,/var/tmp/file2.csv'

endEmail

The endEmail method performs the final processing of the email.

def endEmail(String runDataPrimaryKey, int dataBlockSeq, boolean success, Map<String, String> columnValueMap){
    //Add logic here
}

The runDataPrimaryKey and dataBlockSeq parameters are the same parameters as those used in the startEmail method.

The success parameter will be true if the email is accepted by the email server. However, it does not guarantee that the email has been successfully delivered, as there are several intermediate delivery points before an email reaches its final destination.

This method does not have a return value.

Bulk emails from source

When sending multiple emails with different information, you need to create a Source definition that will choose the relevant data for the emails. Specify the sourceId of the Source definition as a parameter for the email Task. Each row selected from the Source will generate an email with its sender address, recipient addresses, subject, message, and attachments dynamically populated from the Source or using Groovy methods.