Views: 2704
Last Modified: 17.10.2022

Types of email events are described at the page Settings > Service Settings > Email and SMS events > Event types :

To edit email event types, select the Edit item in the actions menu. To add new type, click on the Add a type button at the context menu to open the form:

Enter name for a created type. Checkmark description languages for your new type and fill out the fields Sort, Name and Description. Enter available fields in the Description field (macroses of #SOMETHING# type), to be used in email template message body, belonging to the type created by you.

It's recommended to use a suitable module abbreviation (in our particular case - WF for workflows in bizproc module) as the first part of the name for the email event. This simplifies the navigation in the email event list.

Working using the API

The text below requires some level of coding skill. If you are not sure that you are knowledgeable enough in coding, please consult a skilled developer.

Type of an email event is created either in the Control Panel (as description above) or via API using the method CEventType::Add. The event is called by the method CEvent::Send. Examples of handling these methods can be found in the available documentation. You can also find how to handle specific events in the Bitrix Framework learning course.

Macroses

Macroses for templates of email event messages are taken from type description plus system macroses.

System macroses are values, specified in the Main module settings. There are 4 system macroses in total:

  1. #DEFAULT_EMAIL_FROM# - Website administrator e-mail (default "From" address):,
  2. #DEFAULT_SENDER# - Default sender number field
  3. #SITE_NAME# - Site name field
  4. #SERVER_NAME# - Site URL field.

When calling an event, you don't have to pass values for system macroses, they are inserted by default. But, a custom value passed by a developer will replace the system value.

Macroses from description are sourced from an array declared by the method CEventType::Add.

The macroses themselves are replaced by array values using macros name keys. For example, an event added with array containing the following fields:

array(
	'ORDER_ID' => 123, 
	'ORDER_PAID' => 'Y', 
	'BUYER_NAME' => 'John'
)

Email template can use the fields, via these macroses:

#ORDER_ID#
#ORDER_PAID#
#BUYER_NAME#

Starting from main module version 15.0.7 (with enabled PHP use in email template) the same can be specified as follows:

<=$arParams['ORDER_ID']>
<$arParams['ORDER_PAID']>
<=$arParams['BUYER_NAME']>

Resulting email template body has array of passed fields is accessible via the variable $arParams.

XML tag specifics

Click Save, after which, the new type is added to the general list and it can be specified when creating email templates.

Editing of email event types is available at the new Template tab, containing visible email event templates, binded to this type. This tab will be empty for the newly created type.

Please note that after being created the event type won't be triggered immediately. The developer must call this event type in the required API locations. The administrator who created a new event type must pass the event type name In our case: WF_STATUS_CHANGE , list of values that must be available in the templates of this event as macroses, as well as conditions, when this event must be called In our case - when changing the workflow status to our custom status. .


0


Courses developed by Bitrix24