Bitrix Site Manager

Mail subsystem

Mail subsystem is the technology used to handle e-mail messages within a site.

The mail system operation includes the following stages:

  1. Creating a mail event type. A mail event type can be created using the function CEventType::Add only.
  2. Creating a mail template. Can be accomplished in the administrative menu Mail templates, as well as using the CEventMessage::Add function.
  3. Creating a mail event. A mail event can be created using the function CEvent::Send only.

When a page finishes execution, the function CEvent::CheckEvents is called automatically. This function is used to accomplish the following main tasks:

  1. select unprocessed mail events from the table b_event;
  2. use the above selected events to generate e-mail messages;
  3. send these messages;
  4. write one of the following values as the send result to the table b_event in the field SUCCESS_EXEC:
    • Y - all messages with all mail templates have been successfully sent;
    • F - all messages with all mail templates could not be sent;
    • P - some messages have been sent successfully, while some messages have failed to send;
    • 0 - mail templates could not found;
    • N - the mail event has not yet been processed by the function CEvent::CheckEvents.

Developers can can affect sending messages by modifying the following settings of the Kernel module:

Besides the above parameters, the constant ONLY_EMAIL can be used. If initialized, it allows to send all messages only to the specified address or group of addresses.

Example of creating the mail event type

$obEventType = new CEventType;
    "NAME"          => "Banner status changed",
    "SITE_ID"       => "en",
    "DESCRIPTION"   => "
        #ID# - banner ID
        #CONTRACT_ID# - contract ID
        #TYPE_SID# - type ID

Example of creating the mail template

$arr["ACTIVE"]      = "Y";
$arr["SITE_ID"]     = array("fr","en");
$arr["EMAIL_FROM"]  = "";
$arr["EMAIL_TO"]    = "";
$arr["BCC"]         = "";
$arr["SUBJECT"]     = "Banner #ID# status changed";
$arr["BODY_TYPE"]   = "text";
$arr["MESSAGE"]     = "
Note! Banner # #ID# status changed.
Banner type: #TYPE_SID#
Contract ID: #CONTRACT_ID#
$obTemplate = new CEventMessage;

Example of creating the mail event

$arFields = array(
    "ID"          => 124,
    "CONTRACT_ID" => 1,
    "TYPE_SID"    => "LEFT"
             array("ru", "en"), $arFields);

See Also