Overview
Application Scenario
In most companies, email communication serves as a common and critical communication method. An employee needs to send emails to notify relevant personnel upon task completion. How to realize the effect in FineReport? For example, emails are sent to relevant personnel when a record of data is successfully submitted to a database.
Function Description
You can add a Successful Data Entry event to send emails to the personnel who are responsible for a template upon successful data entry.
Notes
1. After automatic data entry through the task schedule, the Send Email event cannot be automatically executed.
2. If cell values or widget values are used in the Send Email setting, data entry values cannot be obtained dynamically. Only initialized values are available.
Example
Example in this document:
The built-in template LineForm1.cpt, located in FineReport installation directory\webapps\webroot\WEB-INF\reportlets\doc-EN\Form\LineForm, is used.
Upon successful data entry by a submitter, the system will automatically send an email notification to Lisa (the person who is responsible for the template), and CC the notification to the submitter and supplier.
Setting the Sender
An email sender must be set. Otherwise, emails cannot be successfully sent. You only need to set the sender for each decision-making system once.
Log in to the decision-making system as the admin, choose System Management > System Setting > Mailbox, add a sender, set System Default Sender, and click OK, as shown in the following figure.
Note:1. The configuration steps may vary depending on the mail server. For details, see Email Service.
2. After configuration, click Send Test Mail to check whether the email is available.
3. If the default sender of the system is not configured, you cannot set the Send Email event in section "Setting the Sending Email Event." Besides, a prompt saying "Visit the platform or contact the admin to configure the sender mailbox." will be displayed.

Setting the Recipient
In the event, emails need to be sent to Lisa and the submitter. Therefore, you need to bind their email addresses.
Log in to the decision-making platform as the admin, choose System Management > User Management > All Users, click the
icon to edit the user information of Lisa (the sales leader), enter the email address, and click OK, as shown in the following figure.
Note:

After the mailboxes are configured, the following figure shows the effect.

Setting the Sending Email Event
Open the template LineForm1.cpt in FineReport installation directory\webapps\webroot\WEB-INF\reportlets\doc-EN\Form\LineForm.
1. Choose Template > Web Attribute on the menu bar, click Data Entry Setting based on the template preview method, and select Set for This Template Separately from the drop-down list of Following Settings.
2. Click +, select Successful Data Entry, and set Event Type to Send Email.
3. Set the JS code as shown in the following figure, save the setting, and save the template.

The following table describes the JS setting of the Send Email event.
| Setting Item | Description | Example |
|---|---|---|
Recipient CC BCC | You can manually enter the recipient address, and separate multiple recipients with commas (,). Three writing methods are available: 1. Usernames in the decision-making system (Emails will be sent to the mailboxes bound to the users.) 2. Specific email addresses 3. Parameter ${abc} (abc represents the parameter name, and emails will be sent to the corresponding email addresses of the parameter.) | Lisa: Emails will be sent to the mailbox bound to user Lisa. ${fine_username}: Emails will be sent to the mailbox of the current login user. |
Subject | Subject refers to the email subject. The formula ${today()} is supported. | ${today()} Inventory Update |
Body | Body refers to the email body. The formula ${today()} is supported. The parameter ${abc} is supported. | Dear colleagues, please note that our inventory records have been updated. Update Date: ${today()} Update Person:${fine_username} Update Details: Refer to the following part. |
Preview Report Content in Body | The report content is displayed in the email body. | / |
Mounting the Template to the Directory
Log in to the decision-making platform as the admin, and choose System Management > Directory Management > Directory Management, and click Add Template, as shown in the following figure.

Select the template created in section "Setting the Sending Email Event", and click Next.
Set the directory name to Sending Emails upon Successful Data Entry, set the mounting type to Data Entry, and click OK. In this case, the template is mounted to the main directory of the decision-making system.

Assigning Directory Viewing Permissions
Log in to the decision-making system as the admin, choose System Management > Permission Management > Common Permission Configuration, and select a department/role/user as the permission carrier. In this example, Sales department is selected from the department.
Select the Directory Permission tab and assign Sales department the permission to view the directory Sending Emails upon Successful Data Entry, as shown in the following figure.

Effect Preview
Log in to the decision-making system as hanwen (hanwen, 123456), a user of the sales department, and open the directory Sending Emails upon Successful Data Entry.
After data entry of the inventory information, click the Submit button.
1. A pop-up box saying "Success" is displayed, representing successful data entry.
2. A pop-up box saying "Sent Successfully" is displayed, representing that the email is successfully sent.

Meanwhile, hanwen, Lisa, and the supplier all receive the email, as shown in the following figure.

Notes
Problem:
A prompt saying "Sent Failed. Please check the mail server configuration, make sure that the SMTP mail server, username, password, and recipient address are filled in correctly, and make sure the network is smooth." is displayed upon email sending, as shown in the following figure.

Troubleshooting step 1:
The sender is not correctly configured in the decision-making system. For details about how to configure the email server, see section "Setting the Sender."
Troubleshooting step 2:
The manually entered username does not belong to a user included in the data-decision system.
Check whether a manually entered username does not belong to a user included in the decision-making system.
Troubleshooting step 3:
No recipient is selected. Or no mailbox is bound to the selected recipient.
Check whether the recipient is configured. For details about how to configure the recipient mailbox, see section "Setting the Recipient."
Note: