{"id":50126090,"url":"https://github.com/stechstudio/laravel-postmaster","last_synced_at":"2026-05-26T23:01:40.972Z","repository":{"id":359192337,"uuid":"1244941584","full_name":"stechstudio/laravel-postmaster","owner":"stechstudio","description":null,"archived":false,"fork":false,"pushed_at":"2026-05-24T01:58:39.000Z","size":712,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-24T21:03:13.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stechstudio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-20T18:49:59.000Z","updated_at":"2026-05-24T01:58:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"a585d275-161a-4425-ac06-c848a3b16bb7","html_url":"https://github.com/stechstudio/laravel-postmaster","commit_stats":null,"previous_names":["stechstudio/laravel-postmaster"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/stechstudio/laravel-postmaster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-postmaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-postmaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-postmaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-postmaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stechstudio","download_url":"https://codeload.github.com/stechstudio/laravel-postmaster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stechstudio%2Flaravel-postmaster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33494784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-23T20:02:15.117Z","updated_at":"2026-05-26T23:01:40.965Z","avatar_url":"https://github.com/stechstudio.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postmaster\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/stechstudio/laravel-postmaster.svg?style=flat-square)](https://packagist.org/packages/stechstudio/laravel-postmaster)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\n**Provider-agnostic email webhooks and delivery tracking for Laravel.**\n\nYour app sends mail; Postmaster turns every provider's webhook — SendGrid,\nPostmark, Mailgun, Amazon SES, Resend — into one normalized event:\n\n```php\nuse STS\\Postmaster\\EmailEvent;\n\nEvent::listen(function (EmailEvent $event) {\n    if ($event-\u003eisBounced()) {\n        // the address bounced; act on it\n    }\n});\n```\n\nSwitch providers, run several at once, or fail over between them without\ntouching that code. Run the migrations and Postmaster also records every\noutbound email and keeps it current as events arrive — a queryable delivery\nhistory, a self-maintaining suppression list, and a dashboard to browse it\nall.\n\n## What you get\n\n- **One event for every provider.** Every webhook arrives as the same\n  `EmailEvent`, no matter which of the five providers sent it. There's no\n  provider-specific parsing anywhere in your app.\n- **Provider independence.** Your code only ever sees the normalized event, so\n  you can switch providers, run several at once, or fail over between them\n  without changing a line of it.\n- **Verified by default.** Every inbound webhook is authenticated (by\n  signature, token, or basic auth, depending on the provider), and anything it\n  can't trust is rejected.\n- **Delivery tracking out of the box.** Run the migrations and Postmaster\n  records every send and keeps it current from the webhook stream. You get\n  `delivered()`, `bounced()`, and `failed()` query scopes, a full per-message\n  timeline, and an address suppression list that maintains itself.\n- **Emails linked to your models.** Tie a send to an `Order` or a `User` and\n  read its delivery state straight off the model.\n- **A support dashboard.** A gated, cross-tenant UI for searching messages,\n  watching events arrive live, and inspecting any stored email.\n- **Sandbox delivery.** Intercept every outbound email in staging. It's\n  recorded in your app's history but never actually sent.\n\n## Requirements\n\n- PHP 8.3+\n- Laravel 12 or 13\n\n## Installation\n\n```bash\ncomposer require stechstudio/laravel-postmaster\n```\n\nThat's all the setup there is. The webhook route registers itself, and there's\nnothing to publish until you opt into a feature that needs it.\n\n## Getting started\n\nThe core of Postmaster is one webhook endpoint and one event. Two steps and\nyou're reacting to delivery events from any provider.\n\n### 1. Point your provider at the webhook\n\nPostmaster serves `POST /webhooks/postmaster/{provider}`. In your email\nprovider's dashboard, set the webhook URL to:\n\n```\nhttps://your-app.com/webhooks/postmaster/{provider}\n```\n\n…where `{provider}` is `sendgrid`, `postmark`, `mailgun`, `ses`, or `resend`.\n\n### 2. Listen for the event\n\nEvery webhook, from any provider, is dispatched as a normalized `EmailEvent`.\nListen for it in a service provider's `boot()` method:\n\n```php\nuse Illuminate\\Support\\Facades\\Event;\nuse STS\\Postmaster\\EmailEvent;\n\nEvent::listen(function (EmailEvent $event) {\n    if ($event-\u003eisPermanent()) {\n        // Uh oh, a hard bounce or a block. This address won't accept mail again.\n        // What happens next is your call: pause sends, flag the account, alert the team.\n        logger()-\u003ewarning(\"Email permanently failed for {$event-\u003etoAddress()}\");\n    }\n});\n```\n\nThat's the whole integration. Deliveries, opens, bounces, and complaints from\nevery provider all arrive here as one `EmailEvent` with one API.\n\nFor anything beyond a few lines, use a dedicated listener class instead.\nLaravel auto-discovers it, and it can implement\n`Illuminate\\Contracts\\Queue\\ShouldQueue` to process webhooks off the request\ncycle.\n\nFor the common \"alert ops when a hard bounce lands\" case the package ships\na drop-in notification:\n\n```php\nuse Illuminate\\Support\\Facades\\Notification;\nuse STS\\Postmaster\\Notifications\\EmailDeliveryFailed;\n\nEvent::listen(function (EmailEvent $event) {\n    if ($event-\u003eisPermanent()) {\n        Notification::route('mail', config('ops.alerts_to'))\n            -\u003enotify(new EmailDeliveryFailed($event));\n    }\n});\n```\n\nIt renders a short summary (address, status, bounce type, the provider's\nreason). Subclass it to customise the body or to add `database`/`slack`\nchannels.\n\n\u003e **Before you go live**, set up [webhook verification](#securing-webhooks).\n\u003e Postmaster rejects unverified webhooks by default. It's one credential per\n\u003e provider.\n\n## Securing webhooks\n\nPostmaster authenticates every inbound webhook and rejects anything it can't\ntrust. Each provider proves authenticity differently, so configure the one\ncredential yours needs. These are all `.env` values. Nothing to publish.\n\n### SendGrid\n\nEnable the Signed Event Webhook in SendGrid and copy the verification key:\n\n```\nPOSTMASTER_SENDGRID_VERIFICATION_KEY=...\n```\n\n### Mailgun\n\n```\nPOSTMASTER_MAILGUN_SIGNING_KEY=...   # falls back to MAILGUN_SECRET\n```\n\n### Amazon SES\n\nSES delivers events through SNS. Subscribe an SNS topic to\n`webhooks/postmaster/ses`. The package verifies the SNS message signature and\nautomatically completes the subscription-confirmation handshake. No secret to\nconfigure.\n\n### Resend\n\n```\nPOSTMASTER_RESEND_SIGNING_SECRET=whsec_...\n```\n\n### Postmark\n\nPostmark does not sign webhook payloads. Use HTTP basic auth (the default) or a\nURL token:\n\n```\nPOSTMASTER_AUTH_USERNAME=...\nPOSTMASTER_AUTH_PASSWORD=...\n```\n\n### Token or basic auth\n\nAny provider can instead use a shared URL token or HTTP basic auth by setting\nits `auth` to `token` or `basic`:\n\n```\nPOSTMASTER_AUTH_TOKEN=mysecrettoken\n# then append ?auth=mysecrettoken to the webhook URL\n```\n\nEach provider's verification method is its `auth` key in\n`config/postmaster.php`: a built-in authorizer (`token`, `basic`,\n`user-agent`) or a fully-qualified authorizer class. Providers default to\nsignature verification where the provider supports it.\n\n## Verify your setup\n\nWith the webhook pointed and its credential set, confirm the whole round trip:\n\n```bash\nphp artisan postmaster:verify\n```\n\nIt detects your provider from the mail config, shows the exact webhook URL to\nregister, sends a real test email to an address you supply, then watches live\nfor the delivery webhook to come back. It reports each event the instant it\nlands.\n\nThe live watch needs a cache store shared between your CLI and web processes\n(`file`, `redis`, `database`, and so on). With the per-process `array` store\nthe command sends the test email and stops there.\n\n## The EmailEvent\n\nEvery webhook becomes an `EmailEvent` with a normalized API. The methods are\nthe same whatever the provider:\n\n```php\n$event-\u003eprovider();           // \"SendGrid\", \"Postmark\", \"Mailgun\", \"SES\", \"Resend\"\n$event-\u003estatus();             // one of the EmailEvent::STATUS_* constants\n$event-\u003etoAddress();          // the recipient email address\n$event-\u003eproviderMessageId();  // the provider's message id\n$event-\u003eoccurredAt();         // when the event happened (DateTimeImmutable, UTC)\n$event-\u003ebounceType();         // normalized bounce severity, or null\n$event-\u003eisPermanent();        // true for a hard bounce or a block\n$event-\u003eresponse();           // the provider's response/diagnostic detail\n$event-\u003ereason();             // the provider's reason string\n$event-\u003ecode();               // the provider's status code\n$event-\u003eclickedUrl();         // the URL clicked on a click event (else null)\n$event-\u003etags();               // Collection of tags/categories\n$event-\u003edata();               // Collection of custom data\n$event-\u003epayload();            // the raw provider payload\n$event-\u003etoArray();            // everything above as an array\n```\n\n\u003e **A note on provider casing.** Config keys are lowercase identifiers\n\u003e (`sendgrid`, `postmark`, `mailgun`, `ses`, `resend`). Stored and surfaced\n\u003e values are the canonical product name (`SendGrid`, `Postmark`, …). The\n\u003e `provider()` method, the `provider` column, and the dashboard all use the\n\u003e latter.\n\n### Statuses\n\n`status()` returns one of:\n\n`EmailEvent::STATUS_ACCEPTED`, `STATUS_DEFERRED`, `STATUS_DELIVERED`,\n`STATUS_BOUNCED`, `STATUS_DROPPED`, `STATUS_COMPLAINED`, `STATUS_OPENED`,\n`STATUS_CLICKED`. (Plus `STATUS_SENT`, `STATUS_SANDBOXED`, and `STATUS_BLOCKED`\nfor outbound records the package writes itself.)\n\nFor comparing against a single value, every status has a matching `is*()`\npredicate. They make a status check read clearly and they autocomplete:\n\n```php\nif ($event-\u003eisBounced())    { /* … */ }\nif ($event-\u003eisDelivered())  { /* … */ }\nif ($event-\u003eisFailed())     { /* bounced, dropped, or complained */ }\n```\n\nThe same predicates are available on `EmailMessage` (where they answer\nagainst the latest recorded status):\n\n```php\nif ($message-\u003eisFailed())   { /* the latest event was a failure */ }\n```\n\n### Bounce classification\n\nBeyond the action, bounces are normalized into a severity, so you can answer\n\"should I stop mailing this address?\" without provider-specific knowledge:\n\n- `EmailEvent::BOUNCE_HARD`: permanent, and safe to suppress.\n- `EmailEvent::BOUNCE_SOFT`: transient, so retry later.\n- `EmailEvent::BOUNCE_BLOCK`: blocked by reputation or policy.\n\n`bounceType()` returns one of these (or `null` when the event is not a\nbounce). `isPermanent()` is a shortcut for \"hard or block\".\n\n## Invalid payloads\n\nIf a payload can't be turned into a valid event, the `on_invalid` config\nsetting decides what happens: `log` (default), `throw`, or `ignore`.\n\n```\nPOSTMASTER_ON_INVALID=log\n```\n\n## Tracking delivery\n\nEverything above is the core: a verified webhook endpoint and a normalized\nevent.\n\nPostmaster also **records every outbound email** and keeps each record current\nfrom the webhook stream, matching them up by provider message id, so you end\nup with a queryable delivery history. Publish and run the migrations:\n\n```bash\nphp artisan vendor:publish --tag=postmaster.migrations\nphp artisan migrate\n```\n\nThat's it — persistence is on. To run the package as a pure event dispatcher\nwith no database writes, set:\n\n```\nPOSTMASTER_PERSISTENCE=false\n```\n\nThis creates an `email_messages` table. Each row tracks a message's\n`status`, `bounce_type`, `sent_at`, and `last_event_at`. The model\n(`STS\\Postmaster\\Models\\EmailMessage`) is swappable via the\n`postmaster.persistence.model` config key.\n\nIt ships query scopes for the common lookups: `delivered()`, `bounced()`,\n`complained()`, `opened()`, `clicked()`, `sent()`, `accepted()`, `deferred()`,\n`dropped()`, the aggregate `failed()` (bounced, dropped, or complained), and\nthe generic `withStatus()`.\n\n```php\nuse STS\\Postmaster\\Models\\EmailMessage;\n\nEmailMessage::bounced()-\u003ecount();\nEmailMessage::delivered()-\u003ewhere('sent_at', '\u003e', now()-\u003esubDay())-\u003eget();\n```\n\nThe package still dispatches `EmailEvent` in all modes. Persistence is just a\nfirst-party listener layered on top.\n\nWith persistence on, each `EmailEvent` also carries the record it was\ncorrelated to, so a listener can walk straight back to the originating message,\nand through it to your own model:\n\n```php\nuse Illuminate\\Support\\Facades\\Event;\nuse STS\\Postmaster\\EmailEvent;\n\nEvent::listen(function (EmailEvent $event) {\n    $order = $event-\u003eemailMessage?-\u003erelated;   // the Order, User, ... it was sent for\n});\n```\n\n`$event-\u003eemailMessage` is set by the package's own listener, which is\nregistered first, so it is populated for any listener of your own. It is null\nwhen persistence is disabled or the webhook carries no message id to correlate\non.\n\n### Recording the full timeline\n\nThe summary record above keeps only a message's *latest* status. That's enough\nfor \"is this delivered?\" but it can't represent a message that was opened three\ntimes, and it overwrites the history as new events arrive.\n\nWith persistence on, the package also keeps every event as its own row, the\ninitial send and each webhook alike, so a message retains its complete delivery\nhistory. This is on by default; set `POSTMASTER_RECORD_EVENTS=false` to keep\nonly the summary record.\n\nEach `EmailMessage` exposes its timeline, oldest first, via the `events()`\nrelationship. It's ideal for an activity feed:\n\n```php\nforeach ($message-\u003eevents as $event) {\n    // $event-\u003estatus:      sent, delivered, opened, bounced, ...\n    // $event-\u003eoccurred_at: when it happened\n    // $event-\u003ebounce_type, $event-\u003eresponse, $event-\u003ereason, $event-\u003ecode\n}\n```\n\nThe summary record is still maintained alongside the timeline, and still\nadvances only on the newest event, so out-of-order webhooks can't make its\nstatus regress. Query `EmailMessage` for current state, walk `events()` for\nhistory.\n\nTimeline rows accumulate one per event, so pair them with a retention window.\nSet the number of days to keep events and the package schedules a daily prune\nautomatically. It deletes whole rows and leaves the summary records untouched:\n\n```\nPOSTMASTER_PRUNE_EVENTS_AFTER_DAYS=90\n```\n\nYou can also run it on demand:\n\n```bash\nphp artisan postmaster:prune-events\n```\n\n### Tracking address suppression\n\nThe projections so far answer \"what happened to this *message*?\". Suppression\nanswers a different question: should I send to this *address* at all? The\nmessage tables can't answer that cleanly, because a bad address poisons every\nfuture send, not just the message that bounced.\n\nWith persistence on, the package keeps an `email_addresses` table: one row per\nrecipient with a current `status` of `active` or `suppressed`. This is on by\ndefault; set `POSTMASTER_TRACK_ADDRESSES=false` to disable it.\n\nAn address is suppressed automatically on a hard bounce, a spam complaint, or a\ndrop. Soft bounces don't count, since they're transient. Suppression is sticky:\na later delivery or open never revives an address, only an explicit unsuppress\ndoes.\n\nCheck it before sending:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nif (! Postmaster::isSuppressed($email)) {\n    Mail::to($email)-\u003esend(new Invoice($order));\n}\n```\n\nAn address you've never sent to is treated as sendable. You can also manage\nsuppression yourself, for unsubscribes, abuse reports, anything:\n\n```php\nPostmaster::suppress($email);     // optional second arg: a reason string\nPostmaster::unsuppress($email);\n```\n\nThe `EmailAddress` model carries `active()` / `suppressed()` query scopes and\nthe `reason` / `suppressed_at` columns for the rest.\n\n**Suppression is global, never per tenant.** A provider suppresses a\nhard-bouncing address across your whole account regardless of which tenant sent\nthe mail, so a per-tenant view would just disagree with reality.\n\n#### Block suppressed sends automatically\n\nThe check above is opt-in per send. To make every outbound to a suppressed\naddress fail safely at the source, set:\n\n```\nPOSTMASTER_BLOCK_SUPPRESSED=true\n```\n\nAnything addressed to a suppressed recipient is intercepted before it reaches\nthe mail transport, recorded with status `blocked` (so the attempt is visible\nin the dashboard), and dropped. Bypass it per send by lifting the suppression\nor by skipping the check yourself — there's no per-message bypass flag.\n\n\u003e This table is built from the webhooks you receive, so it reflects\n\u003e suppressions caused by mail sent through this package. Pulling a provider's\n\u003e full suppression list, or clearing suppressions back on the provider's side,\n\u003e would need each provider's API and isn't part of this layer.\n\n### Storing message content\n\nBy default a record holds only delivery metadata. Enable content storage and\neach record also keeps a full representation of the email: sender, recipients\n(to/cc/bcc), subject, HTML and text bodies, and attachment filenames. This is\ncaptured from the message itself at send time, so it works the same for every\nprovider.\n\n```\nPOSTMASTER_STORE_CONTENT=true\n```\n\n\u003e Message bodies are large and routinely contain personal data or secrets\n\u003e (password-reset links, magic-login tokens). This is why it's off by default.\n\u003e Attachment **contents** are never stored, only their filenames. And because\n\u003e content is captured before sending, it won't reflect the click-tracking link\n\u003e rewriting some providers apply afterward.\n\nBecause of the size and sensitivity, pair it with a retention window. Set the\nnumber of days to keep content and the package schedules a daily prune\nautomatically. The record is kept; only the content columns are cleared:\n\n```\nPOSTMASTER_PRUNE_CONTENT_AFTER_DAYS=30\n```\n\nYou can also run it on demand:\n\n```bash\nphp artisan postmaster:prune-content\n```\n\nA single email can override the global setting. A Mailable's `Tracking` carries\na `storeContent` field, and the notification `MailMessage` has fluent\n`storeContent()` / `dontStoreContent()` methods. So a password-reset or MFA\nemail can keep its body out of the database even when storage is on, and a\nspecific email can be captured even when it's off:\n\n```php\n// in a Mailable's postmaster() method\nreturn new Tracking(related: $this-\u003euser, storeContent: false);\n\n// on a notification MailMessage\nreturn (new MailMessage)-\u003esubject('Your login code')-\u003edontStoreContent();\n```\n\n### Relating emails to your models\n\nRecorded emails can be linked back to two of your models: the one the email\nis **about** (an `Order`, an `Invoice`) and the one the email is **for** (the\n`User` it was sent to). Keeping these distinct means a user can list every\nemail they've ever received without having to traverse every business record\nthey touch.\n\nAdd the `TracksMailable` trait to a Mailable and declare both with a\n`postmaster()` method that returns a `Tracking` object. It works the same way\nas Laravel's own `envelope()` and `content()`:\n\n```php\nuse Illuminate\\Mail\\Mailable;\nuse STS\\Postmaster\\Concerns\\TracksMailable;\nuse STS\\Postmaster\\Tracking;\n\nclass OrderConfirmation extends Mailable\n{\n    use TracksMailable;\n\n    public function __construct(public Order $order) {}\n\n    public function postmaster(): Tracking\n    {\n        return new Tracking(\n            related: $this-\u003eorder,              // what the email is about\n            recipient: $this-\u003eorder-\u003ecustomer,  // who the email is for\n            tenant: $this-\u003eorder-\u003eaccount_id,   // optional; see Multitenancy below\n            tags: ['billing'],                  // optional; see below\n        );\n    }\n\n    public function envelope(): Envelope { /* ... */ }\n    public function content(): Content { /* ... */ }\n}\n```\n\nPostmaster reads `postmaster()` when the mailable is sent, after a queued job\nis dequeued (so it's queue-safe), and records what the `Tracking` declares.\nEvery field is optional, so declare only the ones that apply.\n\n\u003e Need to set something dynamically instead? `TracksMailable` also exposes\n\u003e `relatedTo($model)`, `forRecipient($model)`, `forTenant($tenant)`,\n\u003e `storeContent()` and `dontStoreContent()`. Call them anywhere before the\n\u003e mailable is sent.\n\nFor apps where every email is to a known `User`, the recipient can be\nresolved from the to-address automatically — declare a resolver once, in a\nservice provider, and skip `recipient:` on every Mailable:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nPostmaster::resolveRecipientUsing(\n    fn ($address) =\u003e User::firstWhere('email', $address)\n);\n```\n\nAn explicit `Tracking(recipient: …)` declaration always wins over the\nresolver — useful when an email about User A is sent to User B.\n\n### Tagging\n\n`Tracking`'s `tags` are Laravel's own mailable tags. Postmaster records them on\nthe message so you can categorise and query your recorded mail:\n\n```php\nEmailMessage::taggedWith('billing')-\u003ebounced()-\u003eget();\n```\n\nBecause they're Laravel's tags, a notification's `MailMessage` sets them with\nits native `tag()` method, and Symfony forwards them to providers whose\ntransport supports tags. Postmaster reads and records whatever is there, so a\nplain Mailable calling `tag()` directly is recorded just the same.\n\nAdd `HasEmailMessages` to the business-record model and `IsEmailRecipient` to\nthe User-side model:\n\n```php\nuse STS\\Postmaster\\Concerns\\HasEmailMessages;\nuse STS\\Postmaster\\Concerns\\IsEmailRecipient;\n\nclass Order extends Model\n{\n    use HasEmailMessages;   // emails this order is *about*\n}\n\nclass User extends Model\n{\n    use IsEmailRecipient;   // emails this user has *received*\n}\n```\n\nBoth traits expose the same shape — `emailMessages()`, `latestEmailMessage()`,\n`emailDeliveryFailed()` — but key off different polymorphic links, so each\nmodel only sees the emails it owns:\n\n```php\n$order-\u003eemailMessages;                        // every email about this order\n$order-\u003eemailMessages()-\u003efailed()-\u003eexists();  // did any of them fail?\n\n$user-\u003eemailMessages;                         // every email this user received\n$user-\u003elatestEmailMessage();                  // the most recent one, or null\n```\n\nBoth associations are carried on the message in-process only, written as\nheaders and read and stripped *before* the email is transmitted, so nothing\nabout the related or recipient model is ever exposed in the outbound email.\n\n\u003e Both use polymorphic relationships. If your models use UUID/ULID primary\n\u003e keys, change `nullableMorphs('related')` and `nullableMorphs('recipient')`\n\u003e to the matching variants in the published migration.\n\n### From a notification\n\nNotifications send through the same mailer, so recording, content capture, and\nstatus correlation all work for notification emails with no extra setup. A\nnotification's `toMail()` returns a `MailMessage` rather than a Mailable, so to\n*associate* one, swap Laravel's `MailMessage` for Postmaster's. It's a drop-in\nsubclass with the same fluent `relatedTo()` and `forTenant()` methods:\n\n```php\nuse STS\\Postmaster\\Notifications\\TrackedMailMessage;\n\npublic function toMail($notifiable)\n{\n    return (new MailMessage)\n        -\u003esubject('Your order shipped')\n        -\u003eline('Your order is on its way.')\n        -\u003erelatedTo($this-\u003eorder)\n        -\u003eforTenant($this-\u003eorder-\u003etenant);\n}\n```\n\nOnly the import changes. Postmaster's `MailMessage` is Laravel's with the\n`WithTracking` trait applied, so every notification builder method\n(`line()`, `action()`, and so on) works unchanged.\n\nAlready maintain your own `MailMessage` subclass? Add the `WithTracking`\ntrait to it directly. It works on anything exposing `withSymfonyMessage()`.\n\nOr, to skip subclassing entirely, pass the `Postmaster` builders straight to\n`withSymfonyMessage()` on a plain `MailMessage`:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nreturn (new MailMessage)\n    -\u003esubject('Your order shipped')\n    -\u003eline('Your order is on its way.')\n    -\u003ewithSymfonyMessage(Postmaster::relatedTo($this-\u003eorder))\n    -\u003ewithSymfonyMessage(Postmaster::forTenant($this-\u003eorder-\u003etenant));\n```\n\n### Multitenancy\n\nIn a multitenant app you'll often want every recorded email tagged with its\nowning tenant, including emails that aren't tied to any `related` model, so a\ntenant can see all of its delivery activity at once.\n\nRegister a tenant resolver, typically in a service provider:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nPostmaster::resolveTenantUsing(fn () =\u003e tenant());\n```\n\nThe resolver may return a tenant model or its key, and is called lazily when\neach email is recorded, so it resolves correctly per request or queued job.\n\nIf tenant context isn't available globally (e.g. inside a queued job that\ndoesn't bootstrap tenancy), a Mailable can declare its tenant explicitly in its\n`Tracking`. That always takes precedence over the resolver:\n\n```php\nclass OrderConfirmation extends Mailable\n{\n    use TracksMailable;\n\n    public function postmaster(): Tracking\n    {\n        return new Tracking(\n            related: $this-\u003eorder,\n            tenant: $this-\u003eorder-\u003etenant,\n        );\n    }\n}\n```\n\nQuery a tenant's activity:\n\n```php\nEmailMessage::forTenant($tenant)-\u003ebounced()-\u003eget();\n```\n\nTo get a `tenant()` relationship on `EmailMessage` (and tenant labels in the\ndashboard), tell Postmaster your tenant model. Register it in a service\nprovider, with no need to publish the config file:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nPostmaster::useTenantModel(App\\Models\\Tenant::class);\n```\n\nOr, if you publish the config, set `persistence.tenant_model` there instead.\n\nA few notes for multitenant setups:\n\n- **Inbound webhooks have no tenant context.** Providers POST to one global\n  URL. Correlation runs by provider message id and deliberately ignores global\n  scopes, so a tenant-scoped model is still updated correctly.\n- **Database-per-tenant:** point `persistence.connection` at a shared\n  connection. The webhook handler can't know which tenant database to write to,\n  so the table must live somewhere globally reachable.\n- The tenant column defaults to `tenant_id` (configurable via\n  `persistence.tenant_column`) and is an `unsignedBigInteger`. Apps with\n  UUID/ULID tenant keys should change its type in the published migration.\n\n## Dashboard\n\nA gated, cross-tenant superadmin view of all recorded email activity. Browse\nand search messages, watch events stream in live, manage suppression. It's\nbuilt for support, and every screen is a linkable URL.\n\nIt's off by default. Enable it, and it mounts at `/postmaster`:\n\n```\nPOSTMASTER_DASHBOARD=true\n```\n\nThe dashboard reads the persistence tables, so it requires the\n[persistence layer](#tracking-delivery) to be enabled.\n\n### Authorization\n\nThe dashboard deliberately shows email across *every* tenant. It's the one\nplace tenant isolation is bypassed by design, so access must be gated. Register\nan authorization callback, Telescope-style, in a service provider:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\n\nPostmaster::auth(fn ($request) =\u003e $request-\u003euser()?-\u003eisSuperAdmin());\n```\n\nWith no callback registered, access is allowed **only in the `local`\nenvironment**, so the dashboard is never unguarded in production by accident.\n\n### Screens\n\n- **Overview.** Headline counts and an activity chart over a selectable\n  timeframe, plus recent-messages and live recent-activity cards.\n- **Messages.** A filterable inbox (status, provider, tag, tenant, recipient,\n  subject, date range). Each message opens to its delivery timeline and stored\n  content, rendered in a sandboxed, CSP-restricted frame. Click events show\n  the URL the recipient clicked, inline on the timeline.\n- **Person view.** Click the Recipient row on a message detail page to land\n  on a page listing every email recorded against that recipient model — the\n  \"all the email a user has received\" view.\n- **Resend.** A button on the message detail page replays the stored email\n  through the configured mailer, keeping the original's related model,\n  recipient, tenant, and tags, plus a `resent` tag of its own. Requires\n  stored content; attachments are not restored.\n- **Activity.** A filterable, paginated stream of every recorded event, drawn\n  from the timeline (on by default with persistence).\n- **Addresses.** The suppression list.\n\nEvery datetime is stored UTC and displayed in the viewer's browser timezone\nby default. A small clock toggle in the header swaps between that and UTC;\nthe choice is per-browser (localStorage). The chart's daily buckets stay\nUTC-anchored either way.\n\nThere are no assets to publish and no CDN. The dashboard serves its own\nstylesheet and its one client-side dependency (Alpine) straight from the\npackage. The path and middleware are configurable under the `dashboard` config\nkey.\n\n## Sandbox delivery\n\nIn a staging environment you often want emails to *appear* in your app, so you\ncan see what was sent, to whom, and with what content, without anything\nactually landing in a real inbox. Sandbox delivery does exactly that:\n\n```dotenv\nPOSTMASTER_DELIVERY=sandbox\n```\n\nWith this set, every outbound email is intercepted before it reaches the mail\ntransport and **never sent**. With persistence enabled it is still recorded,\nwith a `sandbox` status, so it shows up in your app's email history exactly\nlike a real send, including its related model, tenant, and (if content storage\nis on) its rendered body.\n\n```php\nEmailMessage::sandbox()-\u003eget();   // everything intercepted in sandbox mode\n```\n\nA sandboxed message is **terminal**: it never reached a provider, so no\ndelivery/open/bounce webhooks will ever follow. Render the `sandboxed` status\ndistinctly in your UI rather than as a pending send.\n\n\u003e Sandbox is provider-agnostic. It works the same no matter which provider you\n\u003e send through. It needs persistence on to record anything (the default).\n\u003e Without persistence, mail is still suppressed but nothing is stored, at\n\u003e which point Laravel's `log` mailer is the simpler tool.\n\nBecause sandbox silently drops *all* mail, enabling it in `production` is almost\nnever intended. Postmaster logs a warning at boot if it sees that, and\n`postmaster:verify` reports it rather than attempting a round-trip check.\n\nThe `POSTMASTER_DELIVERY` setting is an enum, and `normal` is the default. A\n`redirect` mode, which would send every email to a single catch-all address, is\nreserved for a future release.\n\n## Configuration\n\nThe defaults work out of the box. To change the webhook path, adjust\nper-provider settings, or tweak persistence, publish the config file:\n\n```bash\nphp artisan vendor:publish --tag=postmaster.config\n```\n\nThe webhook route is registered for you. To register it yourself instead, say\non a custom domain or prefix or with your own middleware, set\n`POSTMASTER_REGISTER_ROUTE=false` and call `Postmaster::routes()` from your own\nroute file.\n\n## Custom providers\n\nRegister your own provider at runtime with a resolver closure:\n\n```php\nuse STS\\Postmaster\\Facades\\Postmaster;\nuse STS\\Postmaster\\Provider;\n\nPostmaster::extend('myprovider', function (array $config) {\n    return new Provider('myprovider', MyAdapter::class, fn ($request) =\u003e true);\n});\n```\n\nAn adapter implements `STS\\Postmaster\\Contracts\\Adapter` (extending\n`STS\\Postmaster\\Providers\\AbstractAdapter` covers most of it).\n\n## License\n\nMIT. See [LICENSE.md](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Flaravel-postmaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstechstudio%2Flaravel-postmaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstechstudio%2Flaravel-postmaster/lists"}