Search by

masilia / ibexa-newsletter

masilia

The newsletter of an Ibexa 5 site: subscribers and their lists (double opt-in), campaigns made from Ibexa content and sent through Symfony Messenger, statistics, and an admin to run it all

Package info

github.com/MasiliaLabs/ibexa-newsletter

Type:ibexa-bundle

pkg:composer/masilia/ibexa-newsletter

Statistics

Installs: 4

Dependents: 0

Suggesters: 2

Stars: 0

Open Issues: 0

1.0.0-beta.2 2026-11-30 15:59 UTC

README

The newsletter of an Ibexa DXP 5 site: subscribers and their lists (with a confirmation by e-mail), campaigns made from Ibexa content and sent through Symfony Messenger, statistics, and an admin to run it all.

It replaces the newsletter that was inside masilia/ibexa-blocks (see Coming from masilia/ibexa-blocks); the same table, URLs and behaviour carry over.

What it does: a subscribe form with a confirmation by e-mail (double opt-in) and a proof of consent · subscribers and lists, with import, export and the GDPR rights (access, erasure, purge) · campaigns made of Ibexa contents, previewed, tried, scheduled and sent through Symfony Messenger · counting of openings and clicks (off by default) and the handling of bounces and complaints · an admin page (Admin > Newsletter) · capabilities for the assistant of masilia/ibexa-ai.

Requirements

  • PHP 8.3 or 8.4
  • Ibexa DXP 5.0 (ibexa/core), with doctrine/orm and doctrine/doctrine-migrations-bundle
  • MySQL or MariaDB
  • Symfony Mailer (and Messenger for the campaigns)
  • For the admin page: masilia/ibexa-admin-kit ^0.2

Installation

composer require masilia/ibexa-newsletter:^1.0@beta   # 1.0 is in beta: `@beta` goes away at 1.0.0
php bin/console doctrine:migrations:migrate

Enable Masilia\Bundle\IbexaNewsletter\MasiliaIbexaNewsletterBundle in config/bundles.php (Flex does it), then import the routes: the public ones (subscribe, confirm, unsubscribe, tracking, webhook) and the admin ones (the page and its API; only the siteaccesses of the admin group answer):

# config/routes/masilia_ibexa_newsletter.yaml
masilia_ibexa_newsletter:
    resource: '@MasiliaIbexaNewsletterBundle/Resources/config/routing.yaml'

# config/routes/masilia_ibexa_newsletter_admin.yaml
masilia_ibexa_newsletter_admin:
    resource: '@MasiliaIbexaNewsletterBundle/Resources/config/routing_admin.yaml'

Then build the admin page and give the roles their rights:

php bin/console cache:clear
php bin/console bazinga:js-translation:dump public/assets --merge-domains
php bin/console ibexa:encore:compile

In the admin (Roles), give the module Newsletter (masilia_newsletter): view_subscribers, manage_subscribers, export_subscribers, send. They are personal data and the power to write to people: give them with care.

To send campaigns in the background, route the messages to a transport and run a worker; to send the scheduled ones, run a command from a cron (see Campaigns):

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'Masilia\\IbexaNewsletter\\Campaign\\Message\\SendCampaign': async
            'Masilia\\IbexaNewsletter\\Campaign\\Message\\SendBatch': async
* * * * *  php bin/console masilia:newsletter:send-due
0 3 * * *  php bin/console masilia:newsletter:purge-pending --days=30

and php bin/console messenger:consume async kept alive by your process manager. Without a transport, a campaign is sent inside the request or command that starts it, and the log says so.

Configuration

The settings change from one site to the next: they go under system, for a siteaccess, a group of siteaccesses or default, and a site that does not say one leaves it to its group, then to default.

masilia_ibexa_newsletter:
    system:
        default:
            enabled: true                       # the routes answer 404 on a site that does not turn it on
            from_address: news@example.org      # the address of the site in the registry (masilia/ibexa-sites) comes first
            subject: 'Confirm your subscription to {site_name}'
            list_name: 'our newsletter'          # what the visitor subscribed to, in the page that confirms it
            list_id: default                     # sites that give the same one share their subscribers
            consent_text: 'I agree to receive the newsletter of Acme'   # what the visitor is told: kept as the proof of their consent
            consent_version: '1'                 # change it when the text changes
            mail_tokens:                         # the look of the mails and pages of this site, one value at a time (see Front office templates)
                primary: '#0a7b5c'
                logo_url: 'https://example.org/logo.png'
            rate_limit:
                subscribe: { limit: 5, interval: '1 minute' }     # needs symfony/rate-limiter
            tracking: false                     # allow counting openings and clicks (see Measuring)
    sending: { batch_size: 50, messages_per_minute: 120, max_attempts: 3, confirm_above: 1000 }
    deliverability: { webhook_secret: '%env(default::NEWSLETTER_WEBHOOK_SECRET)%', soft_bounce_limit: 3, soft_bounce_days: 30 }

php bin/console debug:config masilia_ibexa_newsletter shows what is set.

Front office templates

Everything a visitor sees comes from templates the package ships in its standard theme (src/bundle/Resources/views/themes/standard/), the fallback of every design of Ibexa's design engine. A project changes one in two ways, from the lightest.

Template (under templates/themes/<design>/) What it is Variables
emails/newsletter/campaign.html.twig (+ campaign.txt.twig, the text version) the mail of a campaign campaign, subject, preheader, intro_paragraphs, items, subscriber, list_name, unsubscribe_url, tokens
emails/subscription_confirmation.html.twig the mail that asks to confirm an address subscriber, confirmUrl, tokens
emails/subscription_status.html.twig the page after a click on a link of a mail status (success, info, error), title, message, tokens
emails/unsubscribe_confirm.html.twig the page that asks to confirm a departure title, message, button, tokens
modals/subscribe-popup.twig the subscribe window (a native <dialog>) none: it asks masilia_newsletter()

1. Change the look of a site: the tokens. A mail client ignores CSS variables, so the templates write the look of the site in their inline styles. The look is the mail_tokens of the settings, per site, one value at a time (a site that changes primary keeps the other tokens of its group or of default):

Token What it is Default
primary the brand colour: header, buttons #1f4e79
primary_contrast what is written on the brand colour #ffffff
text, muted the body text, the small print #1f2937, #6b7280
background, surface behind the mail, the card that holds it #f3f4f6, #ffffff
link the links the primary
font_family font names and commas, a generic family at the end system fonts
radius the rounding, 0 to 32 (px) 8px
logo_url an https address; none: the name of the site is the header none
masilia_ibexa_newsletter:
    system:
        site_group:                 # the default look of the sites of this group
            mail_tokens: { primary: '#191761', font_family: 'Inter, Arial, sans-serif' }
        africa_integrates_group:    # one site changes only what differs (the group `<identifier>_group` of a site of masilia/ibexa-sites, or a siteaccess)
            mail_tokens: { primary: '#0a7b5c', logo_url: 'https://africa.example.org/logo.png' }

A value that is not a #rgb / #rrggbb colour, a plain font list, a radius or an https address is ignored (the default stays): nothing a project writes can inject CSS or HTML. The campaign is made in the scope of its site, so its mail wears that site's tokens; the admin preview shows them. The window wears them as CSS variables (--masilia-newsletter-*), which a theme may also set in its own CSS.

2. Replace a template altogether. Write the same path under templates/themes/<design>/: the design engine finds it before the package's (a design overrides it for itself and the designs below it). Nothing in the configuration names a template, and a campaign has none of its own.

The subscribe window. It is a native <dialog> with a plain script and a plain stylesheet (bundles/masiliaibexanewsletter/front/, installed by assets:install): no build, no dependency, whatever the theme. Any element with data-masilia-newsletter-open opens it (<button data-masilia-newsletter-open>Subscribe</button>). The layout of the design includes it from its modals block, which masilia/ibexa-blocks leaves empty ({% block modals %}{% include "@ibexadesign/modals/subscribe-popup.twig" ignore missing %}{% endblock %}); it shows nothing on a site that has not turned the newsletter on. masilia_newsletter() gives a template enabled, siteName, listName, consentText, subscribeUrl and tokens.

Subscribers, lists and consent

  • A subscriber has a status read from what they did: pending (not confirmed), confirmed, unsubscribed, or rejected (an address that bounced or complained: it is never written to again, and the visitor who tries it again is not told).
  • A list is what people subscribe to (masilia_newsletter_list): its identifier is the list_id of the sites, so the sites that give the same one share it. A list is made the first time somebody subscribes to it.
  • Each subscription keeps a proof of consent (masilia_newsletter_consent): the date, the address of the visitor made too coarse to point at a person (the last byte of an IPv4 address, everything after the first 48 bits of an IPv6 one), the text they were told and its version, and the way they came (form, import, admin). Erasing a subscriber erases their proofs.

The admin API and the policies

The pages of the admin (the next step) talk to a JSON API under /api/masilia/newsletter of the admin siteaccesses. Import its routes from the application:

# config/routes/masilia_ibexa_newsletter_admin.yaml
masilia_ibexa_newsletter_admin:
    resource: '@MasiliaIbexaNewsletterBundle/Resources/config/routing_admin.yaml'
Route Does Policy
GET /lists, GET /subscribers?list=&status=&q=&page=&limit= the lists with their counts; a page of subscribers view_subscribers
POST /lists, PATCH/DELETE /lists/{identifier} make, rename, delete (not while it has subscribers) manage_subscribers
PATCH /subscribers/{id}, POST /subscribers/{id}/confirmation, DELETE /subscribers/{id} rename or move to a list; ask a pending subscriber to confirm again; delete with the proofs of consent manage_subscribers
POST /subscribers/import a CSV (email, name): a preview by default (what is new, existing, duplicated, invalid, with line numbers), written with "preview": false manage_subscribers
GET /subscribers/export the subscribers (under the same filters) as a CSV, streamed; cells that a spreadsheet would run as a formula are written as text export_subscribers

A write carries the CSRF token of the admin in the X-CSRF-Token header. The module masilia_newsletter has four functions: view_subscribers, manage_subscribers, export_subscribers and send (for the campaigns). They are personal data: give them with care, and "all functions" to administrators only.

An imported person is pending (no mail is sent; a confirmation is asked from the admin) unless the administrator attests that every person of the file consented ("attested": true): they are then confirmed, and the proof of consent says so.

Sites and lists

A list belongs to sites; a campaign speaks for one siteaccess (a language) of a site. In Admin > Newsletter > Lists, the dialog of a list has a Sites picker: each siteaccess is under its site (the names come from the registry of masilia/ibexa-sites when it is installed; without it each siteaccess is a site). A siteaccess has one list: choosing it for a list takes it from the one it had. That choice is kept in the database and comes before the list_id setting, which stays the answer for a siteaccess that has no link; the subscribe form of a site and the campaigns of its siteaccesses follow it.

The Site filter narrows the subscribers (and their export), the campaigns and the lists to what a site's siteaccesses have. A filter only narrows: a role limited to some sites never sees more through it.

Rights by site

Each function of the module masilia_newsletter accepts the SiteAccess limitation, which the role editor of the admin offers and fills like any other: a role limited to site_fr covers the campaigns of that site and the list of that site (its list_id; sites that give the same one share it), and nothing else. Without a limitation a role covers everything, as before.

  • Subscribers and lists: the tab shows the lists of the allowed sites and the people in them; searching, editing, moving, erasing, importing, exporting and downloading the data of a person in another list is refused (403). Making a new list needs a role with no limitation (lists come with sites); a list that no site has is for those roles only.
  • Campaigns: only the campaigns of the allowed sites are listed; making, changing, previewing, trying, scheduling, sending, cancelling, reading the numbers of a campaign of another site is refused, and the site choice offers the allowed sites only.
  • The assistant runs as the user and goes through the same rules. The commands (masilia:newsletter:*) are not limited: they are for the people who run the server.
  • To give a site to an editor: Roles > the role > Policies > Newsletter / Send campaigns (or another function) > Edit limitation > SiteAccess. Give each site its own list_id (masilia_ibexa_newsletter.system.<scope>.list_id) if you want its people kept apart; sites that keep the default share one list.

The admin page

Admin > Newsletter (for who has view_subscribers) has two tabs, built with the components of masilia/ibexa-admin-kit:

  • Subscribers: a filter bar (search an address or a name, a list, a status), the table with its pages, and per person: edit (name, list), ask again to confirm (pending only), delete (with a confirmation). Import a CSV reads the file first and says what it holds (new, already there, repeated, lines that cannot be used with their line number); nothing is written until you confirm, and you can attest that everyone consented. Export a CSV downloads what the filters show.
  • Campaigns (for who has send; the tab is not drawn for anyone else): make and edit a campaign (name, subject, preview line, list, site, introduction, contents picked with the content browser of the admin and put in order), preview it (the mail in a frame that runs nothing, and its text version), send a test to 1 to 5 addresses, schedule it, send it (a dialog says how many people get it and cannot be undone; for a list over sending.confirm_above you type the name of the campaign), follow it (the page refreshes while it is going out), read the report (how many were sent, failed, waiting, and the ones that failed with the reason), try the failed ones again, cancel it.
  • Lists: the lists with their counts (a click on the number shows their people), make, rename, delete an empty one.

What the user may do depends on the policies; buttons they may not use are not drawn. To set it up in the host (after the routes of the API above):

  1. php bin/console cache:clear, then php bin/console bazinga:js-translation:dump public/assets --merge-domains (the bundle adds its translation domain masilia_ibexa_newsletter to the ones published to the scripts).
  2. php bin/console ibexa:encore:compile (the entries are in Resources/encore/ibexa.config.js). The page route masilia.ibexa_newsletter.list is in the same routing_admin.yaml.

Privacy (GDPR)

  • Right of access: Admin > Newsletter, the download button of a person (export_subscribers), or php bin/console masilia:newsletter:export-subscriber <email>: everything that is kept (the subscriber and the proofs of their consent) as JSON. The confirmation token, a secret of the mails, is not in it.
  • Right to erasure: the delete button of a person, or php bin/console masilia:newsletter:erase-subscriber <email> (every list; asks first, --force without a terminal). The subscriber and the proofs of their consent are deleted, and a trace that holds nothing about the person (the list, the date, the way: admin, cli or purge) is kept in masilia_newsletter_erasure, to be able to say that erasures were made.
  • Storage limitation: php bin/console masilia:newsletter:purge-pending --days=30 [--list=fr] [--dry-run] erases, like any erasure, the subscriptions that were never confirmed. Put it in a cron (daily is enough).
  • The address of the visitor is never kept whole: the last byte of an IPv4 address, everything after the first 48 bits of an IPv6 one, is zeroed before it is stored in a proof of consent.

The campaigns API

Under /api/masilia/newsletter/campaigns, all of it needs the policy send (viewing the subscribers is not enough): GET (the campaigns, the siteaccesses to choose from), POST (make), GET|PATCH|DELETE /{id} (a campaign with its report; edit while it has not started; delete one that has not gone out), GET /{id}/preview (the mail without a personal link), POST /{id}/test (1 to 5 addresses, marked as a test), POST|DELETE /{id}/schedule, POST /{id}/send, POST /{id}/cancel, POST /{id}/retry. Sending says how many people the person saw ("recipients": 123): if the list has changed since, it is refused and asked again; for a list bigger than sending.confirm_above the name of the campaign must be typed too ("confirm"). A campaign that cannot be made (a missing template, a site without a sender) is refused at that point, not found out by the worker for each person.

Measuring and deliverability

Openings and clicks are off. Two switches must both be on: the site (masilia_ibexa_newsletter.system.<scope>.tracking: true — say it only when your consent text tells the people) and the campaign (the box "Count openings and clicks"). Then the links of a real mail (not a preview or a test) go through /newsletter/click/<signed token>, which notes the click and redirects, and a 1-pixel image /newsletter/open/<token>.gif notes the opening. The link that unsubscribes is never rewritten, the text version keeps the real addresses, and a link not signed by this application is a 404 (the redirect cannot be used to send people elsewhere). The tokens are signed with kernel.secret: changing it stops the links of mails already sent. A mail client that loads images by itself counts as an opening: the number is an upper bound. Leaving by the link of a campaign mail is counted for that campaign.

Bounces and complaints. Set a secret and tell your provider to call the webhook:

masilia_ibexa_newsletter:
    deliverability:
        webhook_secret: '%env(default::NEWSLETTER_WEBHOOK_SECRET)%'   # unset or empty: the webhook is off (404)
        soft_bounce_limit: 3      # an address that bounces "for now" this many times…
        soft_bounce_days: 30      # …in this many days is refused
Provider Address How the call is proven
any (your own function, SES behind a Lambda…) POST /newsletter/webhook/generic, body {"type": "hard_bounce" | "soft_bounce" | "complaint", "email": "…"} or a list X-Newsletter-Signature: sha256=<HMAC-SHA256 of the body with the secret>
Postmark (Bounce, Spam complaint) /newsletter/webhook/postmark?token=<secret> the token
Brevo /newsletter/webhook/brevo?token=<secret> the token
Mailgun /newsletter/webhook/mailgun Mailgun's signature, with its webhook signing key as the secret; calls older than 15 minutes are refused

An address that bounced for good, or complained, is refused from then on in every list that has it: it gets nothing more (what waited for it is skipped), and a visitor who tries to subscribe with it is not told. Events are kept for the dashboard with the campaign whose mail they were about.

The numbers

In the report of a campaign (Campaigns tab): mails sent, failed, waiting; bounces (for good, for now), complaints and who left from that mail, each with its rate of the mails sent; and, when the campaign was measured, the people who opened it and followed a link, with the links that were followed. Export the numbers (CSV) gives the same as a spreadsheet. In the Lists tab each list has a growth view: who subscribed and who left, day by day over 7, 30, 90 or 365 days, with the figures of every status today. API: GET /campaigns/{id}/stats and /stats.csv (policy send), GET /lists/{identifier}/stats?days=30 (policy view_subscribers).

The assistant

With masilia/ibexa-ai installed (it is only a suggestion), the assistant of the admin can work the newsletter, each capability on the tier of what it does and behind the Ibexa policy it needs:

Capability Tier Policy Does
newsletter.lists.list, newsletter.subscribers.count read view_subscribers the lists and how many people by status (numbers only)
newsletter.subscribers.list access administrator the latest subscribers (personal data)
newsletter.campaign.draft write send a campaign as a draft from Ibexa contents; nothing is sent
newsletter.campaign.preview read send the mail as it would go out, and how many people it goes to
newsletter.campaign.test_send write send a test to 1 to 5 addresses
newsletter.campaign.send destructive send sends it for real; the card of approval says how many people; refused if the number given is not the list's now
newsletter.campaign.report read send the campaigns, or the numbers of one

The skill tells it to draft, preview, test, and send only on an explicit go-ahead. masilia:ai:os:selftest runs them (it sends nothing, not even a test) and deletes its draft.

Campaigns: how a mail goes out

A campaign has a name, a subject, an introduction (plain text, in paragraphs), Ibexa contents, a list and the siteaccess it speaks for. It is draft, scheduled, sending, sent or cancelled; only a draft or a scheduled one can be changed.

  • Rendering. The mail is made in the scope of the campaign's siteaccess: its sender (from_address), its design, its languages. The template is always emails/newsletter/campaign.html.twig, found through the design engine (see Front office templates: the colours of the site are its mail_tokens, and a design replaces the template by writing the same path; campaign.txt.twig next to it is the text version, else the text is made of the HTML). It gets campaign, subject, preheader, intro_paragraphs, items (each: title, summary, image, url, and the Ibexa content), subscriber, list_name, unsubscribe_url and tokens. A content that is not published, is hidden or is gone is left out. Contents are not rendered through the views of the site (they need a request, and a worker has none): the template draws the items. The links of the mail (the one that leaves the list, the tracking, and the contents) are on the site that serves them, with its host and language prefix as Ibexa resolves them for the siteaccess: nothing to configure, and the same from the admin and from a worker. The scheme (https) is the one of the router's context: set framework.router.default_uri (e.g. DEFAULT_URI=https://example.org) in production, since a worker has no request to tell it. Settings of the siteaccess: summary_fields, image_fields, image_variation.

  • Sending. queue() marks the campaign as going out and queues SendCampaign; that lists the people (the confirmed ones of the list, one line each, never two for a person), then SendBatch messages write to them sending.batch_size at a time, at sending.messages_per_minute (the next batch waits). Each mail is claimed before it is written, so a batch handled twice, or by two workers, writes it once. A person who left in the meantime is skipped. A mail that failed keeps its reason and is tried again by retry (up to sending.max_attempts). The mails carry List-Unsubscribe and the one-click List-Unsubscribe-Post.

  • Workers. Route the messages to a transport, or they are handled at once in the process that queued them (and the log says so):

    framework:
        messenger:
            routing:
                'Masilia\IbexaNewsletter\Campaign\Message\SendCampaign': async
                'Masilia\IbexaNewsletter\Campaign\Message\SendBatch': async
  • Commands. masilia:newsletter:send <id> [--inline] [--yes] (--inline writes the mails in this process at the set pace, and takes up a campaign that stopped halfway), masilia:newsletter:send-due (the scheduled campaigns whose date has come: put it in a cron, every minute or five), masilia:newsletter:cancel <id>.

masilia_ibexa_newsletter:
    sending: { batch_size: 50, messages_per_minute: 120, max_attempts: 3, confirm_above: 1000 }

Coming from masilia/ibexa-blocks

The newsletter of masilia/ibexa-blocks (up to 0.9) is this package, with the same rows (the table app_subscriber is adopted by the migrations and renamed masilia_newsletter_subscriber: nothing is copied or made twice), the same URLs, and the same behaviour.

  • Settings: masilia_ibexa_blocks.newsletter.*, masilia_ibexa_blocks.rate_limit.subscribe and masilia_ibexa_blocks.forms.from_address are not read any more (and masilia/ibexa-blocks 0.11 refuses the first two): move them to masilia_ibexa_newsletter.
  • Routes: api_subscribe, subscription_confirm, subscription_unsubscribe and subscription_unsubscribe_confirmed are now masilia_ibexa_newsletter_subscribe, …_confirm, …_unsubscribe and …_unsubscribe_confirmed. The URLs are the same.
  • Contract: Masilia\Contracts\IbexaBlocks\Subscribers is Masilia\Contracts\IbexaNewsletter\Subscribers.
  • Templates: the confirmation mail, the status page and the page that asks to unsubscribe are found at fixed paths (see Front office templates); the package now ships a default for each, and the subscribe window.

Support and contributing

License

MIT, see LICENSE.