Views: 2755
Last Modified: 23.01.2023
Mail subsystem is the technology used to handle e-mail messages within a site.
The mail system operation includes the following stages:
- Creating a mail event type. A mail event type can be created using the function CEventType::Add only.
- Creating a mail template. Can be accomplished in the administrative menu Mail templates, as well as using the CEventMessage::Add function.
- 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:
- select unprocessed mail events from the table b_event;
- use the above selected events to generate e-mail messages;
- send these messages;
- 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 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:
$obEventType = new CEventType;
$obEventType->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:
$arr["ACTIVE"] = "Y";
$arr["EVENT_NAME"] = "ADV_BANNER_STATUS_CHANGE";
$arr["SITE_ID"] = array("de","en");
$arr["EMAIL_FROM"] = "admin@site.com";
$arr["EMAIL_TO"] = "admin@site.de";
$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;
$obTemplate->Add($arr);
?>
Example of creating the mail event:
$arFields = array(
"ID" => 124,
"CONTRACT_ID" => 1,
"TYPE_SID" => "LEFT"
);
CEvent::Send("ADV_BANNER_STATUS_CHANGE",
array("de", "en"), $arFields);
?>
Related links: