Community程式設計與開發github.com

Taldres/laravel-waitlist 郵件發送

為 taldres/laravel-waitlist 整合發送郵件:雙重 opt-in 確認、偏好頁面連結、歡迎郵件、啟動郵件和電子報,僅發送給已同意的人,並附帶正確的取消訂閱連結、一鍵標頭和按專案區分的寄件人。

laravel-waitlist 郵件發送 是什麼?

此技能定義了 laravel-waitlist 套件中所有郵件發送的行為與實作指南。它涵蓋了雙重 opt-in 確認信、管理偏好頁面連結、可選的歡迎郵件、啟動郵件以及電子報等六類郵件,每類郵件都有明確的觸發事件(如 EntrySubscribed、ManageLinkRequested、EntryConfirmed)和應攜帶的連結(如 confirmUrl、unsubscribeUrl、manageUrl)。技能強調使用 Laravel 隊列與加密監聽器(ShouldQueue + ShouldBeEncrypted),以確保回應時間一致且承載令牌的 payload 安全。它同時說明了如何透過 `recipients()` 方法僅取得已同意的收件人,避免在未檢查同意狀態下直接查詢所有條目。對多專案場景,技能提供了從專案設定中動態選取寄件人與郵件驅動程式的模式,並確保郵件連結指向正確的專案頁面。此外,它列出了常見的反模式,例如在一般郵件中放入管理連結、或使用會取消整個列表訂閱的電子報連結,以幫助開發者避免錯誤。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Taldres/laravel-waitlist/tree/HEAD/resources/boost/skills/laravel-waitlist-mail

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Laravel Waitlist:郵件

當使用 taldres/laravel-waitlist 的應用程式需要向等待清單上的人員發送任何郵件,或為其設定郵件提供者時,使用此技能。

主要目標

  • 流程所需的每封郵件都從一個已排隊、加密的監聽器發出,攜帶符合其用途的連結,並且僅送達已取得同意的地址

工作流程

1. 了解何時該發送何種郵件

此套件本身不發送郵件,也不呼叫任何提供者。它觸發事件;應用程式的監聽器透過任何 Laravel 郵件驅動程式(Resend、Postmark、SES、SMTP 等)發送。

郵件觸發時機必須攜帶
確認信(雙重 opt-in)EntrySubscribed 且 $event->requiresConfirmation 為 true$event->confirmUrl、$event->unsubscribeUrl
偏好頁面連結ManageLinkRequested$event->manageUrl,僅發送至 $event->entry->email
歡迎郵件(可選)EntryConfirmed$event->unsubscribeUrl、Waitlist::listUnsubscribeHeaders($event->entry)
關於某個清單的啟動或更新郵件由應用程式決定每個收件人退出該清單的連結
電子報(可選用途)由應用程式決定每個收件人僅取消電子報訂閱的連結

2. 確認信監聽器

namespace App\Listeners;

use App\Mail\ConfirmWaitlistMail;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
use LogicException;
use Taldres\Waitlist\Events\EntrySubscribed;
use Taldres\Waitlist\Facades\Waitlist;

class SendWaitlistConfirmationMail implements ShouldQueue, ShouldBeEncrypted
{
    public function handle(EntrySubscribed $event): void
    {
        if (! $event->requiresConfirmation) {
            return;
        }

        $confirmUrl = $event->confirmUrl ?? throw new LogicException('在 urls() 中設定確認頁面,或啟用套件路由。');

        Mail::to($event->entry->email)->send(new ConfirmWaitlistMail(
            $confirmUrl,
            $event->unsubscribeUrl,
            $event->subscription->consents->pluck('text')->all(), // 正在被確認的內容
        ));

        Waitlist::confirmationMailed($event->subscription, 'confirm-mail@2026-10');
    }
}
  • 相同的事件也會攜帶重發($event->isNewCycle === false)。請勿在監聽器中限制頻率;套件的冷卻時間和上限已處理完畢。
  • confirmationMailed() 會在同意記錄旁記錄郵件的參考資訊;請使用範本名稱與版本,並保留每個版本的文字內容。
  • 當專案的 urls() 未設定 confirm 頁面且套件路由關閉時,$event->confirmUrl 為 null。當連結無法建立(路由已啟用但未註冊,例如路由快取過時之後),會拋出 InvalidConfigurationException 並撤銷註冊或確認:此時沒有任何內容被提交,因此不會觸發事件,也不會有郵件待發。

3. 偏好頁面連結監聽器

use Taldres\Waitlist\Events\ManageLinkRequested;

class SendManageLinkMail implements ShouldQueue, ShouldBeEncrypted
{
    public function handle(ManageLinkRequested $event): void
    {
        Mail::to($event->entry->email)->send(new ManageLinkMail($event->manageUrl, $event->expiresAt));
    }
}

連結在 waitlist.manage.token_ttl 分鐘(60 分鐘)後過期;請在郵件中註明。

4. 啟動郵件與電子報:使用 recipients()

use Taldres\Waitlist\Support\Recipient;

// 一個清單,用於其主要用途:連結可退出該清單
Waitlist::for('beta')->recipients()->each(
    fn (Recipient $recipient) => Mail::to($recipient->email)->locale($recipient->locale)->queue(new LaunchMail($recipient)),
);

// 一個可選用途,全專案範圍內,每個地址僅一次:連結僅取消此用途
Waitlist::recipients('newsletter')->each(
    fn (Recipient $recipient) => Mail::to($recipient->email)->locale($recipient->locale)->queue(new NewsletterMail($recipient)),
);

在 Mailable 中使用收件人的連結:

use Illuminate\Mail\Mailables\Headers;

public function __construct(public Recipient $recipient) {}

public function headers(): Headers
{
    return new Headers(text: $this->recipient->listUnsubscribeHeaders()); // RFC 8058 一鍵取消
}

// 內容:$this->recipient->unsubscribeUrl()

Recipient 擁有 entry、email、purpose、locale(同意記錄的語言,或 null)以及 leavesList。已排隊的 Mailable 會攜帶地址和令牌連結:請讓它們也實作 ShouldBeEncrypted。一鍵標頭需要套件路由和 https 的 APP_URL;如果沒有路由,標頭會是空的。

5. 事件之外的連結

Waitlist::unsubscribeUrl($entry);                // 退出清單
Waitlist::unsubscribeUrl($entry, 'newsletter');  // 僅取消電子報訂閱
Waitlist::listUnsubscribeHeaders($entry, 'newsletter');

6. 多個專案

專案是 $event->entry->project(或 $recipient->entry->project)。從中選取寄件人和郵件驅動程式:

// config/products.php(應用程式自訂):['rocket' => ['name' => 'Rocket', 'from' => '[email protected]', 'mailer' => 'resend'], ...]
$product = config("products.{$event->entry->project}");

$mail = (new ConfirmWaitlistMail(...))->from($product['from'], $product['name']);
Mail::mailer($product['mailer'])->to($event->entry->email)->send($mail);

郵件連結已經指向每個專案自己的頁面(urls())。

規則、參考與範本

  • 每個發送郵件的監聽器都必須實作 ShouldQueue(新地址和已知地址的回應時間一致)和 ShouldBeEncrypted(payload 持有令牌;EntryForgotten 持有地址)。
  • Laravel 透過 app/Listeners 中的 handle() 型別提示自動發現監聽器;如果再使用 Event::listen() 註冊它們,會導致每封郵件被發送兩次。
  • 事件在資料庫提交後分派;已分派的事件並不代表郵件已成功發送,因此請監控失敗的任務。
  • 郵件驅動程式設定:https://laravel.com/docs/mail;請從設有 SPF、DKIM 和 DMARC 的網域發送。
  • 完整指南:https://github.com/Taldres/laravel-waitlist/blob/main/docs/mail.md

範例

  • "使用 Resend 發送雙重 opt-in 郵件":執行 composer require resend/resend-php,設定 MAIL_MAILER=resend、RESEND_KEY=...,然後使用步驟 2 的監聽器。
  • "發送啟動郵件給 beta 清單上的所有人":步驟 4 搭配 Waitlist::for('beta')->recipients()。
  • "發送每月電子報":使用 Waitlist::recipients('newsletter'),並為每個收件人設定一鍵取消標頭。

反模式

  • 在未檢查同意狀態下,使用 WaitlistEntry::all() 或 Waitlist::for($list)->entries() 直接發送郵件;請改用 recipients() 或 whereConsentedTo($purpose)。
  • 將 Waitlist::manageLink($entry) 或管理 URL 放入一般郵件中;這會暴露個人資料,且郵件可能被轉發。
  • 將管理連結發送到 $event->entry->email 以外的任何地址,或用該連結回應請求。
  • 使用會從整個清單取消訂閱的電子報連結:請使用 unsubscribeUrl($entry, 'newsletter') 或 Recipient 自己的連結。
  • 使用同步的郵件監聽器,或未加上 ShouldBeEncrypted 的佇列監聽器。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

Taldres/laravel-waitlist

Use this skill when reviewing Laravel package compatibility across composer constraints, PHP versions, Laravel versions, Testbench versions, dependency stability lanes, Windows CI, or matrix-sensitive code and workflow changes.

Taldres/laravel-waitlist

Use this skill when creating or updating the bundled Laravel Boost skill under resources/boost/skills from the package implementation and package documentation. Trigger after public APIs, commands, config, routes, views, publish tags, README content, or examples change.

Taldres/laravel-waitlist

Use this skill when preparing Laravel package releases: CHANGELOG.md updates, generated release notes, GitHub release workflows, version checks, tags, release validation, or release automation changes. Never publish autonomously.

Taldres/laravel-waitlist

Use this skill when adding Laravel package capabilities or wiring them through the service provider: commands, migrations, routes, config merges, views, translations, assets, middleware, publish tags, workbench files, or console-only behavior.

Taldres/laravel-waitlist

Use this skill when writing, editing, fixing, or reviewing package tests with Pest 4/5 and Orchestra Testbench, including TDD, feature tests, unit tests, type coverage, arch tests, workbench behavior, commands, routes, config, migrations, and publishable resources.

Taldres/laravel-waitlist

Integrate taldres/laravel-waitlist in a Laravel application: define purposes, lists and fields, build the signup form, send the confirmation mail from events, add a preference page, and keep consent, retention and encryption intact.

Taldres/laravel-waitlist

Build the pages of a taldres/laravel-waitlist integration: the signup form with the registered wording, and the confirm, unsubscribe and preference pages, either in Laravel controllers (Blade, Livewire, Inertia) or in an SPA or static site over the package's JSON API, including CORS and bot protection.

Taldres/laravel-waitlist

Turn a taldres/laravel-waitlist waitlist into a launch: invite people in batches in signup order, let invited addresses register, announce the launch to everyone who agreed, and erase the list once its purpose is fulfilled.

Taldres/laravel-waitlist

Operate a taldres/laravel-waitlist installation: answer access and erasure requests, withdraw a purpose on request, apply retention, erase a list once its purpose is fulfilled, rotate APP_KEY with waitlist:rekey, export a list, and check the setup before going live.

Taldres/laravel-waitlist

Run the waitlists of several products in one Laravel app with taldres/laravel-waitlist projects: define projects, scope facade calls with project(), resolve the project of HTTP signups, send mail per project, handle requests across all projects, or keep projects in a database for a central waitlist API.

Taldres/laravel-waitlist

Keep a newsletter tool such as Brevo, Mailchimp or Mailcoach in step with a taldres/laravel-waitlist waitlist: add confirmed contacts per purpose, remove them on withdrawal and erasure, and carry unsubscribes made at the provider back into the waitlist via a webhook.

Taldres/laravel-waitlist

Build waitlist statistics with taldres/laravel-waitlist: signups and confirmations per day for charts, totals and confirmation rates for a period, the confirmed count on any past day, and how many people are on a list right now, for dashboards, admin pages and API endpoints.

Taldres/laravel-waitlist

Write feature tests for an application's taldres/laravel-waitlist integration: get the plain tokens from events, assert the confirmation and other mails, test the signup, confirm and unsubscribe flows in PHP and over the package's HTTP routes, and bypass rate limits and bot checks in tests.

相關技能