NEWSLETTER STUDIO 1.0.0 for SMF 2.1
by BoredSkull - https://boredskull.net
ISC licence

Write, schedule and track email newsletters from your forum, run automated
email series, and manage subscribers, lists and sign-up forms. Hook-based:
no SMF files are edited.

Admin > Configuration > Newsletter Studio


FEATURES

Writing
 - Write in SMF's own editor (BBCode), or in raw HTML (administrators only).
 - Four responsive designs (Classic, Bold header, Minimal, Plain letter), plus
   your own HTML designs. Logo, accent colour and postal address in Settings.
 - Merge tags: {name}, {first_name}, {email}, {forum_name}, {forum_url},
   {date}, {unsubscribe_url}, {preferences_url}, {web_version_url}. They work
   in subject lines too. Name tags take their own fallback:
   {first_name|friend}, {name|reader}.
 - Live content blocks filled in when the email is sent: {block:topics},
   {block:popular}, {block:events}, {block:members}, {block:stats}, plus
   {block:gallery} and {block:questions} with the companion mods. Add a count:
   {block:topics:8}. Blocks only ever show what a guest could see.
 - Two roundup blocks in the editor: {block:since_last_issue} selects topics
   posted since the most recent completed public issue started sending.
   The first issue uses the latest topics. {block:unanswered} selects unlocked
   public topics awaiting a first reply. Both support counts, e.g.
   {block:unanswered:8}, and disappear when there are no matching topics.
 - Preview text (preheader), desktop/mobile preview, test sends to up to five
   addresses. Previews and test sends keep original links and omit tracking
   pixels and personal subscriber controls.
 - "Before you send" checklist: subject length, spammy words, missing preview
   text, unknown tags, Gmail's 102 KB clipping limit, http images, missing alt
   text, empty audience, missing postal address. Errors block sending, including an A/B test whose chosen metric is disabled.

Audiences
 - Lists that people choose (public or hidden, optional double opt-in per list).
 - Existing subscribers adding a double-opt-in list receive a list-specific
   confirmation link valid for seven days. Their current lists stay active.
 - Forum members, filtered by membergroups (primary, additional and post
   groups), post count, registration age, last visit (active or inactive),
   language, club and trust level.
 - Lists and member filters can be combined; every address gets one copy.
 - Respects SMF's own "receive newsletters" preference.
 - Optionally skips people who haven't opened or clicked in the last N emails.
 - Resend to non-openers: one click on a sent campaign's report makes a new
   draft for people who received it but neither opened nor clicked it.
 - Live "this will reach about N people" count while you build the audience.

Sending
 - Send now or schedule for a date and time in your own time zone.
 - Built-in batching through SMF's scheduled tasks (every five minutes), with
   per-run, hourly and daily limits. No cron job is required, though one helps
   on quiet forums.
 - Pause, resume, cancel, or push the next batch by hand.
 - A/B subject line tests: a sample gets A or B, the winner (by opens or
   clicks) goes to everyone else after the wait you choose.
 - One-click unsubscribe headers (RFC 8058 List-Unsubscribe), as now required by
   Gmail and Yahoo for bulk senders, plus List-Id and Feedback-ID headers.
 - A clean plain-text part in every email (no stray CSS or entity codes).
 - The author gets a short email summary when their newsletter finishes
   sending (can be turned off).
 - A run that dies mid-send can't leave a campaign stuck: unfinished rows are
   marked failed after 15 minutes, never sent twice.

Automations
 - Email series that start when someone subscribes (to any or one list),
   registers on the forum, or hasn't visited for N days (win-back).
 - Each email is sent a set number of hours or days after the start.
 - Content blocks in automation emails are refreshed daily.
 - New-member emails wait until the account is activated.

Reports
 - Sent, open rate, click rate, click-to-open, unsubscribes, bounces.
 - First-48-hours timeline, links clicked (clicks and people), latest activity,
   A/B results.
 - CSV export of every recipient with sent/opened/clicked times.
 - Why people unsubscribed: an optional one-question survey after
   unsubscribing (too many emails, not relevant, never signed up, other).
 - Dashboard: subscribers, growth over 30 days, average engagement, queue,
   and health warnings (task disabled, task not running, no postal address).

Subscribers
 - Search and filter by status, list, source and engagement; bulk actions.
 - Each subscriber's history and consent record (when, from where, the wording
   they agreed to).
 - Import from CSV or pasted text (header detection, "Name <email>",
   semicolons, BOM), either sending a confirmation email or recording how they
   already agreed. Export to CSV. Imports don't start welcome automations
   unless you tick the box.
 - Suppression list: bounced, complained and blocked addresses are never
   emailed and can't be re-added by imports or forms.

Sign-up forms
 - Form builder: heading, intro, lists (optionally let people choose), name
   field, consent checkbox, button, thank-you message or redirect, double
   opt-in.
 - Use them as a hosted page, an iframe on any website, plain HTML, a box under
   the board index, or beside the newsletter archive.
 - Bot protection: honeypot, signed time token, per-visitor rate limit.
   Replies are the same for "already subscribed" and "blocked", so forms can't
   be used to probe addresses.

Subscriber self-service (works even on members-only forums)
 - Unsubscribe page with a confirm button (mail scanners can't unsubscribe
   people by opening the link), and "resubscribe" if clicked by mistake.
 - Double opt-in confirmation also needs a button press, so link scanners
   can't confirm addresses on their own.
 - Preference centre: choose lists, change name, unsubscribe from everything,
   download my data (JSON), delete my data.
 - Members also get Profile > Newsletters.

Bounces
 - Webhook for Amazon SES (via SNS, including the subscription handshake),
   Mailgun, Postmark, SendGrid, Brevo and a simple generic JSON format.
 - Hard bounces and complaints are suppressed at once; soft bounces after a
   limit you set. Bounces are credited to the campaign that caused them.

Archive
 - Public archive of sent newsletters at ?action=newsletters, with an RSS feed,
   optional menu button and a sign-up form beside it. Archive copies have no
   tracking and no personal details.

Privacy
 - Open and click tracking can be turned off per campaign or by default.
 - IP addresses: not stored, anonymised (default) or full.
 - Activity history kept for a set number of days.
 - Unconfirmed sign-ups expire after a week.
 - Deleting someone keeps only a hash of their address, so they can't be added
   back by mistake.
 - Web versions and previews are served with a strict Content Security Policy,
   so newsletter HTML can never run scripts on the forum.

Permissions
 - "Write and send newsletters" and "Manage newsletter subscribers" can be
   given to non-admin groups (Admin > Permissions). Raw HTML editing, designs,
   settings and integrations stay with administrators.


BOREDSKULL ECOSYSTEM

Everything is optional and detected automatically. Each can be switched off
under Integrations.

 - Clubs: send to the members of chosen clubs.
 - Trust Levels: send only to members at or above a trust level.
 - Media Gallery: {block:gallery} with the latest uploads from public,
   non-club albums at the root or directly under a public root album.
 - Questions & Answers: {block:questions} with open and popular questions,
   with Open/Solved badges.
 - Community Digest: a "Latest newsletter" section in members' digests
   (through integrate_community_digest_sections).
 - AI Assistant: subject line and preview text suggestions, first drafts from
   a short brief, and polishing, in the editor.
 - Activity Stream: posts each public newsletter when it finishes sending, if
   your build offers ActivityStream::publish().

The table and column names used for these are in NewsletterIntegrations::$map
at the top of Sources/Newsletter-Integrations.php. If your builds use
different names, change them there. Queries against other mods use
db_error_skip, so a mismatch hides a feature instead of breaking a send. If a
campaign asks for clubs or a trust level and the mod isn't available, the
campaign goes to nobody rather than everybody.


HOOKS FOR OTHER MODS

integrate_newsletter_blocks (&$blocks)
	$blocks['name'] = callable($count) returning email-safe HTML.
	Use it in a newsletter as {block:name} or {block:name:count}.

integrate_newsletter_sent ($campaign)
	Called when a campaign finishes sending.


HOW SENDING WORKS

A scheduled task, "Newsletter Studio", runs every five minutes. Each run starts
scheduled campaigns, picks A/B winners, sends up to "Emails per run" (within
the hourly and daily limits) and marks finished campaigns. Once a day it also
enrols win-back members, refreshes automation emails and prunes old history.

SMF runs scheduled tasks when people visit. On a quiet forum, add a server
cron job that runs SMF's cron.php every five minutes using the forum's PHP CLI,
for example: php /path/to/forum/cron.php

Mail goes through SMF's sendmail(), so it uses your forum's mail settings
(PHP mail or SMTP). For large lists, an SMTP service such as Amazon SES,
Mailgun, Postmark or SendGrid is strongly recommended; point its bounce
webhook at the address shown under Suppression.

Tracking, unsubscribe, preferences and forms are served by nl.php in the forum
root, which uses SSI so they keep working on members-only forums and during
maintenance.


INSTALL / UNINSTALL

Install through the Package Manager. A starter list ("Newsletter") and a
sign-up form are created the first time.

Uninstalling removes the hooks and files and disables the scheduled task. Tick
"Remove all data" to also delete the tables, settings and permissions.


CHANGELOG

1.0.0 - First public release.
