The add-on enables creating and configuring outbound email templates containing a constant body and variable parameters. A template is created in the visual HTML designer or by using reports. The add-on provides a visual HTML editor with the extensive set of HTML elements.
Sending emails from templates can be set as a reaction to different events in your application. You can preset recipients, configure parameters and upload attachment files to be sent with emails.
Key features:
See sample application using this add-on. See webinar on the CUBA Platform channel.
The add-on can be added to your project in one of the ways described below. Installation from the Marketplace is the simplest way. The last version of the add-on compatible with the used version of the platform will be installed. Also, you can install the add-on by coordinates choosing the required version of the add-on from the table.
In case you want to install the add-on by manual editing or by building from sources see the complete add-ons installation guide in CUBA Platform documentation.
Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
Go to CUBA -> Marketplace in the main menu.
Find the Email Templates add-on there.
Click Install and apply the changes. The addon corresponding to the used platform version will be installed.
Open your application in CUBA Studio. Check the latest version of CUBA Studio on the CUBA Platform site.
Go to CUBA -> Marketplace in the main menu.
Click the icon in the upper-right corner.
Paste the add-on coordinates in the corresponding field as follows:
com.haulmont.addon.emailtemplates:yet-global:<add-on version>
where <add-on version>
is compatible with the used version of the CUBA platform.
Platform Version | Component Version |
---|---|
7.2.x | 1.4.2 |
7.1.X | 1.3.1 |
7.0.X | 1.1.3 |
6.10.X | 1.0.3 |
Click Install and apply the changes. The add-on will be installed to your project.
You can use the following component features.
The component enables you to create, edit and remove email templates.
To open Email template browser press Email templates in the Administration menu.
There are two ways to create email template: from report and from designer.
The following parameters are available for editing:
If the report type is a report with an entity you can set entity for a template. In addition, you can set report parameters.
If the report type is a report with entities you can set entities for a template. In addition, you can set report parameters.
The following parameters are available for editing:
The screen contains the following elements:
This type of creating template provides the ability to use HTML editor. You can design a template with different elements and set every element, using Setting panel.
See more information about using the editor in README
for GrapesJs HTML editor.
To add parameters and value formats go to the Parameters and Formats tab.
To create parameters automatically from template use Create from template button in the Parameters section.
See the complete parameter guide in CUBA Platform. Report Generator | External Report Parameters.
See the complete value format guide in CUBA Platform. Report Generator | Field Value Formats.
You can add or remove attachments on the Attachments tab for both types of templates: from report and from designer. You can attach a report or a file.
You can set the following parameters for a report attachment:
To open group browser click Groups in the Email templates browser. The screen enables you to create, edit or remove email template groups.
To create or edit the group enter the name of the group.
After setting groups, you can specify a group for a template.
The add-on enables creating custom blocks. Go Administration -> Email templates and click the Blocks button.
To create a new block click the Create button and in the Template Block editor screen you can move predefined HTML elements and change them on the canvas. Or you can see and set HTML code on the HTML tab.
You can put the created custom block to the predefined groups or create your own. Go Administration -> Email templates and click the Blocks button and then Groups button.
Your created custom HTML elements will appear in the Email template editing screen while creating an email template from designer.
To send an email select a template in the list and click Send.
The following parameters are available for editing:
The To field is required. You can select entity or entities for the report and set report parameter.
A developer can use the following methods from EmailTemplatesAPI:
EmailInfo generateEmail(EmailTemplate emailTemplate, List<ReportWithParams> params)
EmailInfo generateEmail(EmailTemplate emailTemplate, Map<String, Object> params)
void checkParameterTypeChanged(ReportInputParameter inputParameter, ParameterValue parameterValue)
The EmailTemplate
entity contains subject, body, and attachments. It also contains from, to, cc, bcc addresses.
The ReportWithParams
is a wrapper class that represents a report and a map of parameters for that report.
The ParameterValue
is a class that provides a string representation of the parameter with alias and type.
The ReportInputParameter
is a class of Reporting component.
The EmailInfo
is a class of CUBA EmailService
.
Email templates API contains builder that can create and fill EmailTemplate
entity.
EmailTemplateBuilderImpl
is an implementation of EmailTemplateBuilder
that provides intermediate methods for
setting and adding email template properties. It also contains terminal methods that can build EmailTemplate
,
generate or send EmailInfo
.
A copy of the specified EmailTemplate
is created in the constructor. Every intermediate method fills the created copy.
public EmailTemplateBuilderImpl(EmailTemplate emailTemplate) {
this.emailTemplate = cloneTemplate(emailTemplate);
}
The build()
method creates the copy from the copy inside builder. It is necessary to save a state of the existed entity or builder.
Example of using the builder:
EmailTemplate newTemplate = emailTemplatesAPI.buildFromTemplate(emailTemplate)
.setSubject("Test subject")
.setTo("address@haulmont.com")
.setBodyParameter("entity", someEntity)
.setAttachmentParameters(reportsWithParams)
.build();