Skip to content

[WEBSITE-723] Add a Personal reply template that threads with the automation's last email - #87

Merged
zackkatz merged 7 commits into
developfrom
feature/website-723-personal-reply
Dec 4, 2026
Merged

zackkatz merged 7 commits into
developfrom
feature/website-723-personal-reply

Conversation

@zackkatz

@zackkatz zackkatz commented Dec 4, 2026

Copy link
Copy Markdown
Member

A founder check-in that follows a marketing email in an automation can now go out as a real reply: "Re: ", In-Reply-To and References pointing at the earlier email, and the earlier email quoted below in Gmail's format. Mail apps then show one conversation, like a person replying to their own newsletter. Pick "Personal reply" in the template picker, next to "Personal". Nothing is chosen per email: the reply goes to the contact's last sent email from earlier in the same run of that automation. With nothing to reply to, it goes out as a plain Personal email under its own subject.

For review: the reply changes PHPMailer's shared Mailer to smtp for one SES send and puts it back afterwards. Check that no path leaves it in smtp mode for a later email.

Part of WEBSITE-723

What changed

  • PersonalTemplate: a second template, gk_personal_reply, rendered and untracked exactly like gk_personal.
  • PersonalReply (new):
    • Message-ID: for every automation email, it reads the Message-ID from the SES (SendRawEmail) or Mailgun response through http_api_debug. SES and Mailgun replace WordPress's own.
    • What it stores: the Message-ID in fc_meta, with the From that actually went out. In automations that have a reply step, it also stores the sent HTML, with the open pixel removed and links untracked.
    • Building the reply: for a reply email, it finds the earlier email in the current run (fc_funnel_subscribers.created_at). It then sets the subject, the two headers and the quote.
    • Why a stored copy: FluentCRM clears a sent email's body. A new render would show today's copy, prices and carts.
    • PHPMailer mode: Gravity SMTP's SES connector builds the email with PHPMailer in mail mode, which encodes headers over 47 characters. A reply switches it to smtp mode on gravitysmtp_after_connector_init, except when the email has a Bcc. It switches back at the next send and on the log update.
    • Duplicate headers: Gravity SMTP drops a header whose value repeats another's, so on a first reply References is moved to a string key.
    • Fallbacks: each reply row says what it replied to, or why it fell back.
    • Clean-up: rows are deleted with their contact and after 180 days.
    • Off switch: wp option update customcrm_personal_reply_off 1.
  • deploy.yml: the class check also covers classes the bootstrap calls statically.
  • composer.json: config.platform.php is set to 7.4, so the dev install resolves for the plugin's minimum PHP. Neither composer.lock nor vendor/ is committed or deployed.
  • AGENTS.md covers:
    • how it works and when it falls back;
    • monitoring queries and a stop rule;
    • the live-test pass criteria;
    • what to re-check after a Gravity SMTP update.

Blast radius

  • Touches:
    • new class PersonalReply, and the new template ID gk_personal_reply;
    • hooks this plugin adds to: fluent_crm/email_headers, wp_mail, http_api_debug, gravitysmtp_after_connector_init, gravitysmtp_email_attribute_headers, gravitysmtp_after_mail_updated, fluentcrm_before_subscribers_deleted.
    • Nothing public is changed or removed.
  • Used by: none outside fluent-crm-custom-features (internal gravitykit.com plugin).
  • Customer code: none (internal plugin; customers don't install it).
  • Docs: none (no published page describes FluentCRM templates).
  • Risk: Contained. Only emails using the Personal reply template change. Every other automation email gains a marker header (removed before sending) and one stored row. Production sends about 1,800 automation emails a month.

Release: none (internal gravitykit.com plugin). No readme.txt or version header bump in this repo.

Tests

  • Unit tests: php84 vendor/bin/phpunit passes 296 tests. The full suite also passes on PHP 7.4. Removing each protection fails its test: current run only, the stored quote, the pixel strip, mode restore, Bcc, sent From, the off switch and cleanup batching.
  • Local, FluentCRM 3.3.5 + Gravity SMTP 2.3.3 (production's version): I used the real SES connector, with only the HTTP call to AWS faked. Its raw MIME went to Mailpit. The emails went through FluentCRM's own sender.
Result
First reply Subject: Re: <earlier>, In-Reply-To and References = earlier Message-ID, unencoded
Reply to a reply Same "Re:" subject; References lists both earlier IDs
Quote The sent copy (FluentCRM had cleared the body), no open pixel, no tracked links
New run of the automation Own subject, no reply headers, no quote
PHPMailer after each reply Back in mail mode
  • Pre-mortem: a separate reviewer listed the ways this could fail. Every item is resolved or documented in /Users/zackkatz/Dropbox/MonoKit/reports/pre-mortem-20261204-002557/report.md.
  • After deploy: a temporary two-step automation sent only to Zack: a hello@ email, a wait, then a Personal reply. It passes when Gmail's "Show original" Message-ID equals the stored id, and the reply threads in Gmail and Apple Mail.

Owner for the first week: Zack.

Abilities: none. Internal site plumbing.

… email

A founder check-in reads as a reply when it follows a marketing email: "Re:" subject,
In-Reply-To/References and the earlier email quoted below, so mail apps show one
conversation. The earlier email is the contact's last sent one from the same
automation, found automatically.

SES and Mailgun replace WordPress's Message-ID, so each automation email's real one is
read from the provider response (http_api_debug) and stored in fc_meta. Gravity SMTP's
SES connector builds the email with PHPMailer in mail mode, which encodes headers over
47 characters; a reply switches it to smtp mode for that email only. Gravity SMTP also
drops a header whose value repeats another's, which removed References on a first reply.

With no earlier email or no stored Message-ID, the email goes out as a plain Personal
email under its own subject.

Part of WEBSITE-723
Reads the earlier email's body in the same query that finds it, skips the header split
for emails without the marker, tracks the PHPMailer switch as a flag, unserializes
stored headers with FluentCRM's safeUnserialize, and registers both Personal templates
in one loop.

Part of WEBSITE-723
FluentCRM clears a sent email's body, so the reply quoted a new render of the campaign:
today's copy, prices and carts, and cart merge tags could create a new discount code.
In an automation with a Personal reply step, each email's sent HTML (pixel removed,
tracked links restored) is now stored with its Message-ID and quoted as sent. The
earlier email must also come from the contact's current run, so a second cart or
renewal run never replies to last year's email.

PHPMailer goes back to mail mode at the start of every send, since the log status
update that restored it never fires with Gravity SMTP logging off, and a reply with a
Bcc stays in mail mode because smtp mode leaves Bcc out of the built email. References
keeps 8 IDs, under PHPMailer's 982-character encoding limit. A fallback with an earlier
email but no stored Message-ID is logged, and customcrm/personal_reply/enabled turns the
reply feature off on its own.

Part of WEBSITE-723
The check only matched 'new \CustomCRM\...', so a missing class behind a static
register() call, such as PersonalReply, would pass it and fatal on the site.

Part of WEBSITE-723
…sender

Each Personal reply's stored row now names the email it replied to, or why it went
out as a plain Personal email (no_earlier_email, no_message_id, no_subject,
database_error), so fallbacks can be counted with SQL. The From stored with each email
is the one in the SES or Mailgun request, since Gravity SMTP can replace FluentCRM's,
and the quote's "wrote:" line uses it.

Stored rows are deleted with their contact (fluentcrm_before_subscribers_deleted) and
after 180 days by a daily event, in batches. The option customcrm_personal_reply_off
turns the feature off with WP-CLI, no deploy needed.

Part of WEBSITE-723
Without a platform pin, an install on PHP 8.x picks doctrine/instantiator 2.x, whose
typed constants break the PHPUnit run on 7.4, the plugin's minimum. composer.lock and
vendor/ are not committed or deployed, so this changes test tooling only.

Part of WEBSITE-723
@linear-code

linear-code Bot commented Dec 4, 2026

Copy link
Copy Markdown

WEBSITE-723

@zackkatz
zackkatz merged commit b18b93a into develop Dec 4, 2026
1 check passed
@zackkatz zackkatz mentioned this pull request Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant