Q: How to dynamically set the recipient of an email? June 28, 2024
How can I dynamically set the recipient of a task during runtime? For instance, reading the email address from a table and having the system send the report generated by the task to that email address.
A: June 28, 2024

Yes. You can utilize the variable feature of SQLMessenger to dynamically set the recipient's email address for the task.

Assuming the recipient's email address is stored in the "mail_addr" column of the "t_admin" table in your database, you can configure the task to dynamically determine the recipient's email address during its execution as follows:

Step1: Create a variable in the task configuration to read the variable value from the 'mail_addr' column of 't_admin'

Step2: When setting the task recipient, click the "From A Variable" button and select the variable created in the previous step

After deploying the task configuration, the system will read the data from the 'mail_addr' column in the 't_admin' table as the recipient address when the task is executed.

Note: The system will add all addresses retrieved by the SQL statement of the variable to the recipient list. Therefore, when configuring the SQL statements of the variable, please ensure to use query conditions in the WHERE clause to limit the search results. For example:

SELECT mail_addr
FROM   t_admin
WHERE  employee_name = 'Andy' --Query only the email address of a specific employee
; 

Using Variables in Tasks, Setting Recipients for Tasks

If the answers provided above do not resolve your issue, please contact us, and we will offer further solutions tailored to your needs.