Skip to content

Mail Web is a Laravel package which catches emails locally for debugging

Notifications You must be signed in to change notification settings

appoly/mail-web

Repository files navigation

MailWeb

A powerful Laravel email debugging and testing tool

Total Downloads Latest Stable Version License

πŸš€ Overview

MailWeb is a robust Laravel package that revolutionizes email development and debugging. It seamlessly captures and displays your application's outgoing emails in real-time, making email testing and sharing effortless.

✨ Features

  • πŸ“§ Real-time Email Interception: Catch and inspect outgoing emails instantly
  • 🎨 Modern UI: Beautiful, responsive interface for easy navigation
  • πŸ” Powerful Search: Quickly find emails with advanced search capabilities
  • πŸ”„ Email Sharing: Share email previews with your team effortlessly
  • πŸ“Ž Attachment Support: Handle email attachments with flexible storage options
  • πŸ›‘οΈ Secure Access Control: Granular control over who can access the dashboard
  • πŸ“± Mobile Responsive: Optimized interface for both desktop and mobile devices

πŸ“‹ Requirements

  • PHP 8.1 or higher
  • Laravel 9.21|10.0|11.0|12.0

πŸ”§ Installation

  1. Install via Composer:
composer require appoly/mail-web
  1. Run migrations:
php artisan migrate
  1. Publish config (if needed):
php artisan vendor:publish --tag=mailweb-config --force

βš™οΈ Configuration

1. Route Registration

Add to your routes file:

Route::mailweb();

2. Access Control

By default, access to the MailWeb dashboard may be restricted to local environments. To control access in specific environments (like production or staging), you should define a Gate in AppServiceProvider (Laravel 11+) or AuthServiceProvider.

The gate name must be 'view-mailweb'. You can choose the logic that best fits your workflow below.

Option 1: Allow Specific Emails (via .env)

This is the most flexible method for small teams. It allows you to grant access via your .env file without redeploying code.

1. Add to your .env file:

MAILWEB_ALLOWED_EMAILS="admin@company.com,developer@agency.com"

2. Add to your config/services.php file:

'mailweb' => [
    'authorized_users' => explode(',', env('MAILWEB_ALLOWED_EMAILS', '')),
]

3. Add to AppServiceProvider::boot():

use Illuminate\Support\Facades\Gate;

public function boot()
{
    Gate::define('view-mailweb', function ($user = null) {
        // Get emails from mailweb config, split by comma
        $allowed = config('services.mailweb.authorized_users', []);
        
        // Check if user is logged in AND their email is in the list
        return $user && in_array($user->email, $allowed);
    });
}

Option 2: Role or Permission Based

If your application uses a role management system (like a role column, is_admin boolean, or Spatie Permissions), use that as your source of truth.

Add to AppServiceProvider::boot():

use Illuminate\Support\Facades\Gate;

public function boot()
{
    Gate::define('view-mailweb', function ($user = null) {
        // Example: Check a boolean column
        // return $user && $user->is_admin;
        
        // Example: Check a specific role string
        // return $user && $user->role === 'admin';
    });
}

Option 3: Open Access (Local/Staging Only)

Use this if you want to allow everyone (including guests/non-logged-in users) to view the emails, but only on specific environments.

Add to AppServiceProvider::boot():

use Illuminate\Support\Facades\Gate;

public function boot()
{
    Gate::define('view-mailweb', function ($user = null) {
        // ⚠️ Allows anyone to view emails if the environment matches
        return app()->environment('local', 'staging');
    });
}

3. Local Development

For local development, set in your .env:

MAIL_MAILER=log

πŸ“ Usage

  1. Access the dashboard at:
{your-app-url}/mailweb
  1. Configure email storage limit in .env:
MAILWEB_LIMIT=30  # Default value
  1. Set up email pruning (recommended in routes/console.php):
use Illuminate\Support\Facades\Schedule;

Schedule::command('mailweb:prune')->daily();

πŸ’Ύ Attachment Storage

Configure attachment storage in your .env:

MAILWEB_ATTACHMENTS_DISK=s3  # Or any configured disk
MAILWEB_ATTACHMENTS_PATH=/custom/path  # Optional, defaults to /mailweb/attachments

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

Local Development Setup

  1. Clone the repository
  2. Install dependencies:
composer install
  1. Link to your test project - add to your test project's composer.json:
{
    "repositories": [
        {
            "type": "path",
            "url": "../path/to/MailWeb",
            "options": {
                "symlink": true
            }
        }
    ],
    "require": {
        "appoly/mail-web": "@dev"
    }
}
  1. Run composer update appoly/mail-web

πŸ“„ License

This project is licensed under the MIT License.


Made by Appoly

About

Mail Web is a Laravel package which catches emails locally for debugging

Resources

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 9