Skip to content

feat(messaging): deliver email messages to raw email addresses - #12675

Merged
abnegate merged 9 commits into
mainfrom
feat-messaging-send-to-raw-emails
Oct 15, 2026
Merged

abnegate merged 9 commits into
mainfrom
feat-messaging-send-to-raw-emails

Conversation

@abnegate

@abnegate abnegate commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What

Adds an emails parameter to the create (POST /v1/messaging/messages/email) and update (PATCH /v1/messaging/messages/email/:messageId) email message endpoints. It accepts a list of plain email addresses, letting a message be delivered to recipients that are not backed by an Appwrite user, target, or topic.

Why

Today an email message can only target Appwrite-managed recipients (topics, users, or targets). Sending a one-off email to an arbitrary address required first creating a user/target. The emails param removes that requirement.

How

  • Routes (src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/{Create,Update}.php): new emails param validated with ArrayList(new Email()), declared last and appended to app/config/sdks/parameters.lock.json so existing positional SDK calls keep their argument order. The addresses are stored alongside the other email-only fields (cc, bcc, attachments) in the message data, so no schema migration is needed. The "missing recipient" guard treats a non-empty emails list as a valid recipient source on both create and update, and the message_missing_target error description now names emails.
  • Worker (src/Appwrite/Platform/Workers/Messaging.php): sendExternalMessage reads data.emails and threads it into streamRecipients, which yields the raw addresses in bounded pages (MESSAGE_RECIPIENTS_PAGE_SIZE) as addressed [page, true] tuples on the default provider, each address mapped to an empty user id (main's identifier => userId page shape). Raw emails skip the target/subscriber lookups entirely and are deduplicated before chunking, so a repeated address spanning two pages is delivered once. Mixed messages (e.g. a topic plus raw emails) are supported.

Tests

E2E (tests/e2e/Services/Messaging/MessagingBase.php):

  • testCreateEmailToRawEmails: raw emails alone satisfy the recipient requirement, are persisted in data.emails, and malformed addresses are rejected with 400.
  • testUpdateEmailToRawEmails: emails can be set on a draft via PATCH (other data fields preserved), malformed addresses are rejected, and clearing every recipient while un-drafting returns message_missing_target.
  • testSendEmailToRawEmails: full delivery through the worker against the local maildev SMTP server in a fresh project (so maildev is the default provider). Sends to one address listed twice and asserts SENT, deliveredTotal === 1, no delivery errors, and receipt in maildev. Runs on every CI run; no third-party service is called.

Verification

  • Pint: passed (changed files)
  • PHPStan level 4 over src/Appwrite/Platform/Workers/Messaging.php, src/Appwrite/Platform/Modules/Messaging, tests/e2e/Services/Messaging: no errors
  • Rector dry-run (tests/tools/rector.php) on the test file: clean

Not verified locally

  • The e2e suite was not run locally (needs the Docker stack); CI is the authority for the three e2e tests above.
  • No size cap is added to emails. The message data column is 65535 chars; an oversized payload fails the document structure check, which the general error handler maps to general_argument_invalid (400), the same as an oversized cc/bcc list today.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 25, 2026 04:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no outstanding findings.

Summary

Adds support for sending email messages directly to validated raw email addresses that are not backed by Appwrite users, targets, or topics.

  • Extends the email create and update endpoints with an emails parameter persisted under message data.
  • Treats raw addresses as a valid recipient source for non-draft messages.
  • Streams deduplicated raw addresses directly to the default email provider in bounded pages.
  • Adds E2E coverage for creation, validation, persistence, and provider delivery.

Reviews (5) · Last reviewed commit: "chore: merge main into feat-messaging-se..."

@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-messaging-send-to-raw-emails (after).

Metric Before After Change
🚀 Requests/sec 181.98 183.1 ⚪ +0.6%
⏱️ Latency P50 95.27 ms 95.87 ms ⚪ +0.6%
⏱️ Latency P95 223.15 ms 215.78 ms ⚪ -3.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 95.87 215.78 11,400 183.1 -7.37
Account 180.04 306.3 600 10.35 -8.8
TablesDB 92.99 168.87 6,200 103.03 -15.53
Storage 89.16 204.39 3,000 51.09 +14.89
Functions 130.73 252.11 1,600 27.95 +2.13

Top API waits (after)

API request Max wait (ms)
account.name.update 571.49
functions.variables.delete 408.5
functions.variables.update 394.52
functions.delete 385.33
storage.buckets.create 376.58

Add an `emails` parameter to the create and update email message
endpoints so a message can be delivered to plain email addresses that
are not backed by an Appwrite user, target, or topic.

The addresses are stored alongside the other email-only fields (cc, bcc,
attachments) in the message `data`. The worker streams them straight to
the default email provider in bounded pages, skipping the
target/subscriber lookups since raw emails are already delivery
identifiers. A message addressed only to raw emails now satisfies the
recipient requirement.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@abnegate
abnegate force-pushed the feat-messaging-send-to-raw-emails branch from 48b6759 to 3cdceba Compare June 25, 2026 05:13
@abnegate
abnegate changed the base branch from 1.9.x to main June 25, 2026 05:13
Dedupe the raw email list before chunking so a repeated address that
spans two pages is delivered to once, not once per chunk. Add a
regression test covering the cross-page case.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit de9dff3 - 1 flaky test
Test Retries Total Time Details
FunctionsScheduleTest::testDeleteScheduledExecution 1 10.08s Logs

The email message routes moved to the Messaging module, so port the emails
parameter, the recipient guard and the data payload onto
Modules/Messaging/Http/Messages/Email/{Create,Update}.php. Accept main's
removal of tests/unit/Messaging/MessagingFanoutTest.php (dropped on main as
implementation-coupled); the raw-email fan-out stays covered by the
MessagingBase E2E tests.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
AssertEqualsToSameRector rewrites the deliveryErrors count assertion; the
Checks job runs rector in dry-run mode and failed on the diff.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
abnegate and others added 4 commits September 23, 2026 09:39
Resolve the email Create/Update routes and the messaging worker toward
main's shape: main reordered the Create action parameters and changed
streamRecipients to yield [page, perUser] tuples keyed identifier =>
userId, so raw emails now yield an addressed page mapping each address
to an empty user id on the default provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take main's database 8 rename (getMaxUidLength, Id) in the email routes
and re-add the emails param alongside it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SendGrid delivery test only ran when an operator supplied a real
DSN, so CI never exercised the worker path and the credentialed run hit
a production third-party service. A fresh project whose only provider is
the local maildev SMTP server makes that provider the default raw emails
route to, so delivery and deduplication of a repeated address are
asserted on every run. Also cover the update route, and name emails in
the missing recipient error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The latest parameter reordering keeps route declarations, action signatures, and the SDK parameter lock aligned without changing existing parameter order.

Adds raw email-address recipients to email message create and update endpoints, persists them with email message data, and delivers them through the messaging worker. E2E coverage exercises recipient validation, updates, and delivery, while the SDK parameter lock and missing-recipient error description reflect the new API contract.

Latest changes: The latest commits move emails to the end of both endpoint parameter lists and corresponding action signatures to preserve existing SDK parameter order, and update the SDK parameter lock accordingly.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
app/config/errors.php Updates the missing-recipient error description to mention raw email addresses.
app/config/sdks/parameters.lock.json Locks the new emails parameter after existing parameters for create and update endpoints.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Create.php Validates, persists, and accepts raw email recipients when creating email messages.
src/Appwrite/Platform/Modules/Messaging/Http/Messages/Email/Update.php Validates, persists, and accepts raw email recipients when updating email messages.
src/Appwrite/Platform/Workers/Messaging.php Streams raw email recipients to the email provider in bounded, deduplicated batches.
tests/e2e/Services/Messaging/MessagingBase.php Adds E2E coverage for raw-recipient creation, updates, validation, and delivery.

Reviewed the commits since 29d52eb · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@abnegate

Copy link
Copy Markdown
Member Author

@greptileai review

SDKs pass arguments positionally, so inserting emails after targets
would shift cc, bcc and every later argument in existing createEmail
and updateEmail calls. Declaring it last and appending it to the
parameter lock keeps released call sites working.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate
abnegate merged commit 5204588 into main Oct 15, 2026
63 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

2 participants