chrisreedio/laravel-mailosaur
Composer 安装命令:
composer require chrisreedio/laravel-mailosaur
包简介
Mailosaur SDK for Laravel
README 文档
README
Thin Laravel integration for the official Mailosaur PHP SDK. This package registers a singleton MailosaurClient configured from your app’s config/ENV, and exposes it via a simple wrapper class and a facade so you can call the Mailosaur API anywhere in your app.
The PHP usage patterns below are based on the Mailosaur docs: Mailosaur PHP – Find an email.
Requirements
- PHP ^8.3
- Laravel ^10 || ^11 || ^12
Installation
composer require chrisreedio/laravel-mailosaur
Publish the config file:
php artisan vendor:publish --tag="laravel-mailosaur-config"
Set your environment variables (recommended):
MAILOSAUR_API_KEY=your_api_key MAILOSAUR_SERVER_ID=your_server_id # Optional (defaults to "${MAILOSAUR_SERVER_ID}.mailosaur.net") MAILOSAUR_EMAIL_DOMAIN=your-domain.mailosaur.net
The published config config/mailosaur.php reads from these ENV keys:
return [ 'api_key' => env('MAILOSAUR_API_KEY'), 'server_id' => env('MAILOSAUR_SERVER_ID'), 'domain' => env('MAILOSAUR_EMAIL_DOMAIN', env('MAILOSAUR_SERVER_ID').'.mailosaur.net'), ];
How it works
- The service provider creates a singleton instance of
MailosaurClientusingconfig('mailosaur.api_key'). - It wraps the client in
ChrisReedIO\Mailosaur\Mailosaur, which also exposes yourserverIdanddomainfrom config. - A facade alias
Mailosauris registered for convenience.
Usage
You can access the same singleton three ways. Choose what fits your style:
- Facade (convenient):
use ChrisReedIO\Mailosaur\Facades\Mailosaur; // or use the alias: use Mailosaur; $client = Mailosaur::client(); $messages = Mailosaur::messages(); $serverId = Mailosaur::serverId(); $domain = Mailosaur::domain();
- Dependency Injection:
use ChrisReedIO\Mailosaur\Mailosaur; public function __construct(private Mailosaur $mailosaur) {} public function __invoke() { $client = $this->mailosaur->client(); }
- Container helper:
$mailosaur = app(\ChrisReedIO\Mailosaur\Mailosaur::class);
Convenience methods (no server ID needed)
These helpers use your configured MAILOSAUR_SERVER_ID automatically:
// Find a single message matching criteria Mailosaur::getMessage(SearchCriteria $criteria, int $timeout = 10000, ?DateTime $receivedAfter = null, ?string $dir = null): \Mailosaur\Models\Message // Search for messages Mailosaur::searchMessages(SearchCriteria $criteria, int $page = 0, int $itemsPerPage = 50, ?int $timeout = null, ?DateTime $receivedAfter = null, bool $errorOnTimeout = true, ?string $dir = null): \Mailosaur\Models\MessageListResult // List all messages Mailosaur::allMessages(int $page = 0, int $itemsPerPage = 50, ?DateTime $receivedAfter = null, ?string $dir = null): \Mailosaur\Models\MessageListResult // Delete all messages on the configured server Mailosaur::deleteAllMessages(): void // Create a message to a verified email address Mailosaur::createMessage(\Mailosaur\Models\MessageCreateOptions $options): \Mailosaur\Models\Message // Generate a random email address for the configured server Mailosaur::generateEmailAddress(): string
Examples using convenience methods
use ChrisReedIO\Mailosaur\Facades\Mailosaur; use Mailosaur\Models\SearchCriteria; // Get a single matching message $criteria = new SearchCriteria(); $criteria->sentTo = 'anything@' . Mailosaur::domain(); $message = Mailosaur::getMessage($criteria); // Search with timeout and receivedAfter $testStart = new \DateTime(); $result = Mailosaur::searchMessages($criteria, itemsPerPage: 10, timeout: 10_000, receivedAfter: $testStart); // List and delete all $list = Mailosaur::allMessages(itemsPerPage: 10); Mailosaur::deleteAllMessages(); // Generate a random address on the configured server $address = Mailosaur::generateEmailAddress();
Common examples
Find an email (wait for the next matching message)
use ChrisReedIO\Mailosaur\Facades\Mailosaur; use Mailosaur\Models\SearchCriteria; $criteria = new SearchCriteria(); $criteria->sentTo = 'anything@' . Mailosaur::domain(); // Using raw SDK (requires serverId) $message = Mailosaur::messages()->get(Mailosaur::serverId(), $criteria); // Or with convenience method (no serverId needed) // $message = Mailosaur::getMessage($criteria); // e.g. assert subject // expect($message->subject)->toBe('My example email');
Wait with custom timeout and only include messages received after test start
use ChrisReedIO\Mailosaur\Facades\Mailosaur; use Mailosaur\Models\SearchCriteria; $testStart = new \DateTime(); $criteria = new SearchCriteria(); $criteria->sentTo = 'anything@' . Mailosaur::domain(); // timeout in ms, receivedAfter as DateTime $message = Mailosaur::getMessage( criteria: $criteria, timeout: 10_000, receivedAfter: $testStart );
Generate a random email address for the server
use ChrisReedIO\Mailosaur\Facades\Mailosaur; $emailAddress = Mailosaur::generateEmailAddress(); // e.g. "bgwqj@SERVER_ID.mailosaur.net"
Delete all messages on the server
use ChrisReedIO\Mailosaur\Facades\Mailosaur; Mailosaur::deleteAllMessages();
For many more operations (attachments, forwarding, replying, etc.), see the official Mailosaur PHP docs: Mailosaur PHP – Find an email.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
chrisreedio/laravel-mailosaur 适用场景与选型建议
chrisreedio/laravel-mailosaur 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Chris Reed」 「laravel-mailosaur」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chrisreedio/laravel-mailosaur 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chrisreedio/laravel-mailosaur 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chrisreedio/laravel-mailosaur 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel package that provides a simple facade to the USPS Addresses API
Combine the power of Laravel Pulse with Spatie's Health Checks
Provides an interface to Athena EHR's API
Alfabank REST API integration
Oracle HCM Laravel SDK
Provides user level tenant tokens / scoped search keys.
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-12