Integrating 1C-Bitrix with email distribution services

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1173
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    745
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

1C-Bitrix Integration with Email Marketing Services

The built-in Bitrix mailing module (bitrix:sender) handles basic tasks but falls short of specialized services in email deliverability, template editing, A/B testing, and analytics. Integrating with external ESPs (Email Service Providers) — Mailchimp, SendPulse, UniSender, eSputnik — enables using the capabilities of the service while keeping data in Bitrix.

General integration architecture

Regardless of the specific service, the integration addresses three tasks:

  1. Subscriber export — site users who have subscribed are added to the mailing service list.
  2. Segment synchronization — Bitrix user groups (buyers, inactive, VIP) correspond to tags or lists in the ESP.
  3. Reverse synchronization — unsubscribing in the mailing service updates the subscriber status in Bitrix.

Managing subscriptions in Bitrix

Subscriptions are stored in the following tables:

  • b_subscribe — mailing categories.
  • b_subscribe_email — subscriber addresses.
  • b_user_subscribe — mapping of users to categories.

The subscribe event is OnSubscribeSubscribe (module subscribe). Unsubscribe event: OnSubscribeUnSubscribe. Subscribe to these events to synchronize with the ESP.

Passing a subscriber to the ESP

AddEventHandler('subscribe', 'OnSubscribeSubscribe', function($subscribeId, $email, $fields) {
    $espClient = new EspApiClient();
    $user = CUser::GetByLogin($email)->Fetch();

    $subscriberData = [
        'email'      => $email,
        'first_name' => $user['NAME'] ?? '',
        'last_name'  => $user['LAST_NAME'] ?? '',
        'tags'       => getSubscriberTags($user),
        'source'     => 'bitrix_subscribe',
    ];

    $espClient->addOrUpdateContact($subscriberData);
});

function getSubscriberTags(array $user): array {
    $tags = ['site-subscriber'];
    // Add tags based on purchase history
    if (hasOrders($user['ID'])) $tags[] = 'buyer';
    if (isVipClient($user['ID'])) $tags[] = 'vip';
    return $tags;
}

Behavioral segmentation

The value of the integration lies in passing site behavioral data to the mailing service for trigger-based scenarios:

Event in Bitrix Action in ESP
Added item to cart, did not purchase Add to "Abandoned Cart" segment, start sequence
Placed an order Add to "Buyers" segment, start welcome series
No activity for 90 days Add to "Inactive" segment, start reactivation
Birthday in 7 days Add to "Birthday" segment, send personal offer

Events are tracked via OnSaleOrderSaved, OnSaleBasketSaved handlers, and agents for activity checks.

Reverse unsubscribe synchronization

The ESP sends unsubscribe notifications via webhooks. Accept the webhook at a dedicated URL (/bitrix/tools/esp_webhook.php) and update the status in Bitrix:

// esp_webhook.php
$payload = json_decode(file_get_contents('php://input'), true);
$email = $payload['email'] ?? '';
$event = $payload['event'] ?? ''; // 'unsubscribe', 'spam_complaint'

if (in_array($event, ['unsubscribe', 'spam_complaint'])) {
    // Unsubscribe in Bitrix
    $subscribeEmail = CSubscribeEmail::GetByEmail($email)->Fetch();
    if ($subscribeEmail) {
        CSubscribeEmail::Update($subscribeEmail['ID'], ['CONFIRMED' => 'N']);
    }
}

Transactional emails

Order emails (confirmation, status updates) can be sent via the ESP instead of the Bitrix built-in mail server — for better deliverability and analytics. Override the mail event handler in bitrix/php_interface/init.php:

AddEventHandler('main', 'OnBeforeEventSend', function(&$eventFields, &$template) {
    // Intercept the email and send it via the ESP
    $esp = new EspTransactionalSender();
    $esp->send($eventFields['EMAIL'], $template['SUBJECT'], $template['BODY_HTML']);
    return false; // do not send via the built-in SMTP
});
Task Effort
Subscriber export + event handlers 4–6 h
Behavioral segmentation 6–10 h
Reverse unsubscribe synchronization 3–4 h
Transactional emails via ESP 4–6 h