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 원클릭
}
// content: $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은
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로 이중 옵트인 메일 보내기":
composer require resend/resend-php,MAIL_MAILER=resend,RESEND_KEY=..., 그런 다음 2단계의 리스너를 사용하십시오. - "베타 목록의 모든 사람에게 출시 이메일 보내기": 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없이 대기열에 넣은 리스너.