Views: 454
Last Modified: 23.01.2023

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.

    1. 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:

        1. 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 affect sending messages by modifying the following settings of the Main (Kernel) module:

          • Convert Unix new line symbols to Windows format during email sending
          • Convert 8-bit characters in the message header
          • One or comma-separated list of E-mail addresses to receive copies of all the outcoming messages
          • E-mail address in caption
          • Send email event and template identifiers in message

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


          Example of creating the mail event type:

          Add(array(
              "EVENT_NAME"    => "ADV_BANNER_STATUS_CHANGE",
              "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:

          Add($arr);
          ?>
          

          Example of creating the mail event:

           124,
              "CONTRACT_ID" => 1,
              "TYPE_SID"    => "LEFT"
              );
          CEvent::Send("ADV_BANNER_STATUS_CHANGE", 
                       array("de", "en"), $arFields);
          ?>
          

          Related links:




Courses developed by Bitrix24