zemailme / zemail-laravel
The official Zemail Laravel SDK
Requires
- php: ^8.2
- illuminate/support: ^10.0|^11.0
- zemailme/zemail-php: ^1.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
The official Laravel wrapper for the Zemail API. Generate disposable, temporary emails, fetch messages, and manage your account seamlessly from within your Laravel applications.
๐ฆ Installation
You can install the package via composer:
composer require zemailme/zemail-laravel
โ๏ธ Configuration
Publish the configuration file with:
php artisan vendor:publish --tag="zemail-config"
This will create a config/zemail.php file in your app. Add your API key to your .env file:
ZEMAIL_API_KEY=your_api_key_here
๐ Usage
You can access the API fluently using the Zemail Facade.
1. Account & Subscription
Access your account profile, active plan, and API/mailbox usage limits:
use Zemail\Laravel\Zemail; // Get account profile $account = Zemail::account()->get(); echo "Account ID: {$account->id}, Email: {$account->email}, Tier: {$account->tier}\n"; // Get active subscription $subscription = Zemail::account()->subscription(); echo "Status: {$subscription->status}, Tier: {$subscription->tier}\n"; // Get current resource & API usage $usage = Zemail::account()->usage(); print_r($usage->mailboxes); print_r($usage->storage); print_r($usage->developerApi);
2. Domains
List available domains for mailbox creation:
$domains = Zemail::domains()->list(); foreach ($domains->data as $domain) { echo "Domain: {$domain->name} (Types: " . implode(', ', $domain->allowedTypes) . ")\n"; }
3. Mailboxes
List Mailboxes
$mailboxes = Zemail::mailboxes()->list(page: 1, limit: 10); foreach ($mailboxes->data as $mailbox) { echo "Mailbox: {$mailbox->address} (ID: {$mailbox->id})\n"; } if ($mailboxes->hasMore) { echo "Next cursor: {$mailboxes->nextCursor}\n"; }
Create a Random Mailbox
$mailbox = Zemail::mailboxes()->create([ 'type' => 'random', ]); echo "Created random mailbox: {$mailbox->address}\n";
Create a Custom Mailbox
$mailbox = Zemail::mailboxes()->create([ 'type' => 'custom', 'domain' => 'zemail.me', 'username' => 'my-inbox', ]); echo "Created custom mailbox: {$mailbox->address}\n";
Get Mailbox Details
$mailbox = Zemail::mailboxes()->get(123); echo "Address: {$mailbox->address}, Unread emails: {$mailbox->unreadCount}\n";
Delete a Mailbox
$deleted = Zemail::mailboxes()->delete(123); // Returns true on success
4. Emails & Attachments
List Emails in a Mailbox
// List recent emails with optional search query $emails = Zemail::mailboxes()->emails()->list( mailboxId: $mailbox->id, page: 1, limit: 25, search: 'verification' ); foreach ($emails->data as $email) { echo "[{$email->id}] From: {$email->sender} | Subject: {$email->subject}\n"; }
Get Full Email Details
$email = Zemail::mailboxes()->emails()->get($mailbox->id, $emailId); echo "Subject: {$email->subject}\n"; echo "Plain text body: {$email->bodyText}\n"; echo "HTML body: {$email->bodyHtml}\n"; // Inspect attachments foreach ($email->attachments as $attachment) { echo "Attachment: {$attachment->name} ({$attachment->size} bytes)\n"; }
Mark Email as Read
$isRead = Zemail::mailboxes()->emails()->markAsRead($mailbox->id, $emailId);
Get Temporary Attachment Download URL
$download = Zemail::mailboxes()->emails()->getAttachmentDownloadUrl( mailboxId: $mailbox->id, emailId: $emailId, attachmentId: 'att_123' ); echo "Download URL: {$download['url']}\n"; echo "Expires at: {$download['expires_at']}\n";
Delete an Email
$deleted = Zemail::mailboxes()->emails()->delete($mailbox->id, $emailId); // Returns true on success
Note: This package is a lightweight wrapper around the core
zemail-phpSDK. All methods, error handling, and models available in the core SDK are automatically available here via the Facade!
๐งช Testing
composer test
๐ค Contributing
Please see CONTRIBUTING for details.
๐ Security
If you discover any security related issues, please email support@zemail.me instead of using the issue tracker.
๐ License
The MIT License (MIT). Please see License File for more information.