Laravel 包

Mailbox for Laravel: Preview and Test Rendered Email

发布
Mailbox for Laravel: Preview and Test Rendered Email image

Mailbox for Laravel captures outgoing email and displays it inside your application at /mailbox . Built by 红莓 and maintained by Nika Jorjoliani, the package gives developers a local inbox without a separate mail service or process. Its test API also lets you check the message after Laravel renders it.

Set up the local inbox

The package requires PHP 8.3 or later and supports Laravel 10 through 13. Install it as a development dependency, run its install command, and select the mailbox mailer:

作曲家 要求 redberry/mailbox-for-laravel --dev
php 工匠 mailbox:install
邮件发送者 =mailbox

If your staging deploy runs composer install --no-dev , install Mailbox as a regular dependency to use it there.

The install command publishes the assets and configuration and runs the package migrations. The transport captures Mailables, notifications sent by mail, and Mail::raw() messages. By default, captured messages go into a dedicated SQLite database at storage/app/mailbox/mailbox.sqlite . You can instead use an existing database connection or the package's file store.

打开 /mailbox to inspect the inbox. You can switch between HTML, plain-text, and raw message views, preview or download attachments, and search or filter by recipient. The message list updates without a manual refresh.

Mailbox for Laravel dashboard showing the inbox, an HTML email preview, and attachments
Mailbox for Laravel dashboard showing the inbox, an HTML email preview.

Assert against rendered messages

Once your app sends an email through Mailbox, you can assert on the rendered HTML, recipients, and attachments. For an order confirmation, the test might look like this:

使用 Redberry\MailboxForLaravel\Facades\Mailbox ;
邮箱 :: 断言已发送计数 ( 1 (英文):
邮箱 :: firstSent ()
-> 断言有主题 ( 'Order Confirmation' )
-> assertHasTo ( 'buyer@example.com' )
-> 断言InHtml ( 'Order #12345' )
-> assertHasAttachment ( 'receipt.pdf' , 'application/pdf' (英文):

可选 InteractsWithMailbox trait clears captured messages before each test and gives you $this->mailbox() as an alternative to the facade. You can also check the text body, sender, headers, and attachment count. If a test captures several messages, pass a callback to firstSent() to pick one.

Capture mail and deliver it

和 MAIL_MAILER=mailbox , messages go to the dashboard and stop there. To deliver them too, point MAILBOX_DECORATE at one of your configured mailers:

邮件发送者 =mailbox
MAILBOX_DECORATE =smtp

Mailbox is disabled by default in production. Keep your normal production mailer configured. If MAIL_MAILER=mailbox remains set while MAILBOX_ENABLED=false , emails won't be sent.

The dashboard's default gate allows access outside production. On staging, protect /mailbox with authentication and define a restrictive viewMailbox gate. Captured email may contain reset tokens and personal data.

Automatic pruning is off by default. Set MAILBOX_RETENTION_SCHEDULE=true to run daily cleanup for messages past the configured retention period.

For full documentation, configuration options, and the testing API, see the GitHub 存储库 。

Yannick Lyn Fatt 的照片

Laravel News 的特约撰稿人和全栈 Web 开发人员。

Filed in

赞助

laravelcloud logo
Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

访问 Laravel Cloud
Laravel AI SDK and Laravel MCP Security Fixes: Update Now image

Laravel AI SDK and Laravel MCP Security Fixes: Update Now

阅读文章
Count Worker Crashes as Job Exceptions in Laravel 13.34 image

Count Worker Crashes as Job Exceptions in Laravel 13.34

阅读文章
Elastic Bridge: Eloquent-Style Queries for Elasticsearch and OpenSearch image

Elastic Bridge: Eloquent-Style Queries for Elasticsearch and OpenSearch

阅读文章
Laravel Release Cycle: Versions, Support Policy, and Dates image

Laravel Release Cycle: Versions, Support Policy, and Dates

阅读文章
Unlearn.dev goes free for a weekend, October 10 and 11 image

Unlearn.dev goes free for a weekend, October 10 and 11

阅读文章
Tashil: Laravel Subscription Plans and Feature Usage Limits image

Tashil: Laravel Subscription Plans and Feature Usage Limits

阅读文章