Community编程与开发github.com

Taldres/laravel-waitlist 邮件发送

发送 taldres/laravel-waitlist 集成所需的邮件:双重确认、偏好设置页链接、欢迎邮件、发布邮件和新闻通讯,确保发送给已同意的用户,并包含取消订阅链接、一键点击头部和每项目独立发件人。

laravel-waitlist 邮件发送 是什么?

该技能用于处理基于 Laravel 的 waitlist 应用的所有邮件发送需求。它详细说明了如何利用 Laravel 的事件系统,通过队列化且加密的监听器发送各种邮件,包括双重确认邮件、偏好设置页链接、可选欢迎邮件、发布通知以及新闻通讯。它明确要求在邮件中包含正确的取消订阅链接和 RFC 8058 一键点击头部,以确保合规和用户控制。该技能支持任何 Laravel 邮件驱动(如 Resend、Postmark、SES、SMTP),并能够为不同项目配置独立的发件人信息和邮件驱动,实现多项目隔离。关键点包括:所有邮件监听器必须实现 ShouldQueue 和 ShouldBeEncrypted 接口;邮件发送前必须通过 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 等)发送邮件。

邮件触发时机必须携带
确认邮件(双重确认)当 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(负载包含令牌;EntryForgotten 事件包含地址)。
  • Laravel 通过 handle() 方法的类型提示自动发现 app/Listeners 目录下的监听器;如果再用 Event::listen() 注册一次,每封邮件会被发送两次。
  • 事件在数据库提交后触发;事件被触发并不保证邮件已成功发送,请监控失败的任务。
  • 邮件驱动设置:https://laravel.com/docs/mail;从配置了 SPF、DKIM 和 DMARC 的域名发送。
  • 完整指南:https://github.com/Taldres/laravel-waitlist/blob/main/docs/mail.md

示例

  • "用 Resend 发送双重确认邮件":执行 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.

相关技能