Skip to main content

Send Mail Action

Use this action when you want send emails using emails_templates

Setup#

  1. Create the actions

In the workflows database go to the actions table and insert this code

INSERT INTO actions(`name`,`model_name`)
VALUES ('SendMail', 'Kanvas\Packages\WorkflowsRules\Actions\SendMail');
  1. Asociate with the system_module in table rules_workflow_actions, this system_modules_id available the action for use the rules with this system_module. For example, this actions can be used in any model, so you can associate this action with any model.
INSERT INTO actions(`system_modules_id`,`actions_id`) VALUES (1, 1);

Create the Template#

In this example we going to use the user model as entity. You can set the rule to any model;

<html>
<p>Email: {{entity.email}}</p>
</html>

Create the rule#

  1. Create the rule, this rule use the fields params, this fields is a JSON value , look like
{
"template_name":"new_user",
"toEmail":"[email protected]",
"fromEmail":"[email protected]",
"subject":"New User"
}
INSERT INTO `rules`
(`id`,
`systems_modules_id`,
`companies_id`,
`rules_types_id`,
`name`,
`description`,
`pattern`,
`params`,
`created_at`,
`updated_at`,
`is_deleted`)
VALUES (NULL,
'1',
'108',
'1',
'Send Email',
'This is a Rule for Sent email',
'1',
'{\r\n \"template_name\":\"new_user\",\r\n \"toEmail\":\"[email protected]\",\r\n \"fromEmail\":\"[email protected]\",\r\n \"subject\":\"New User\"\r\n}'
,
'2021-08-18 00:00:00',
NULL,
'0');
  1. Create conditions

The list of operators is here

INSERT INTO `rules_conditions`
(`id`,
`rules_id`,
`attribute_name`,
`operator`,
`value`,
`is_custom_attriube`,
`created_at`,
`updated_at`,
`is_deleted`)
VALUES (NULL,
'1',
'id',
'>',
'1',
'0',
'2021-08-23 00:00:00',
NULL,
'0');
  1. Create actions rules The actions used the rules id and the rules_workflow_actions_id for dispatch the rule
INSERT INTO `rules_actions`
(`id`,
`rules_id`,
`rules_workflow_actions_id`,
`created_at`,
`updated_at`,
`is_deleted`)
VALUES (NULL,
'1',
'1',
'2021-05-14 17:40:43',
NULL,
'0');

Note#

In your system maybe the ids are has other values, keep in mind this please.