✉️ Laravel Mail Explorer

Overview

Mailbook

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Mailbook is a Laravel package that lets you easily inspect your mails without having to actually trigger it in your application.

Example screenshot

View demo

Installation

You can install the package via composer:

composer require --dev xammie/mailbook

You can register mails in a new service provider.

php artisan make:provider MailbookProvider

Make sure to return early if your application is not in debug mode.

public function boot(): void
{
    if (! config('app.debug')) {
        return;
    }
    
    Mailbook::add(...);
}

and register it in config/app.php.

'providers' => [
    ...  
       
    /*
     * Application Service Providers...
     */
    App\Providers\MailbookProvider::class,
],

Usage

Before you can view transactional emails in the mailbook you have to register them.

// This will use dependency injection if your mailable has parameters
Mailbook::add(VerificationMail::class);

// Use a closure to customize the parameters of the mail instance
Mailbook::add(function () {
    $user = User::factory()->make();

    return new VerificationMail($user, '/example/url')
});

// You can also use dependency injection in the closure
Mailbook::add(function (User $user) {
    return new VerificationMail($user, '/example/url');
});

Next head over to /mailbook to preview the mailables.

Variants

When creating mails you might have a couple of different scenario's that you want to test for one mail, you can use variants to solve this.

// Use a closure to customize the parameters of the mail instance
Mailbook::add(OrderCreatedMail::class)
    ->variant('1 item', fn () => new OrderCreatedMail(Order::factory()->withOneProduct()->create()))
    ->variant('2 items', fn () => new OrderCreatedMail(Order::factory()->withTwoProducts()->create()));

Using the database

Most of the time your mailables will need database models. Sometimes you will even preform queries when rendering these mailables. You can safely use factories and other queries when registering your mailables. Mailbook will automatically rollback these changes after rendering.

// All database changes are rolled back after rendering the mail.
Mailbook::add(function (): OrderShippedMail {
    $order = Order::factory()->create();
    $tracker = Tracker::factory()->create();
        
    return new OrderShippedMail($order, $tracker);
});

By default, mailbook will roll back any database changes that are executed while rendering the mails. If you don't have a database connection, or if you don't want it to rollback you can disable it in the config.

'database_rollback' => false,

Customization

You can publish the config file with:

php artisan vendor:publish --tag="mailbook-config"

This is the contents of the published config file:

return [
    'route_prefix' => '/mailbook',
    'database_rollback' => true,
    'display_preview' => true,
    'refresh_button' => true,
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="mailbook-views"

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.

Comments
  • Bump ramsey/composer-install from 1 to 2

    Bump ramsey/composer-install from 1 to 2

    Bumps ramsey/composer-install from 1 to 2.

    Release notes

    Sourced from ramsey/composer-install's releases.

    2.0.0

    Added

    • Use --prefer-stable with lowest dependencies (#178)
    • Allow use of a custom cache key (#167)
    • Allow ability to ignore the cache

    Changed

    Fixed

    • Fix case where working-directory did not run composer install in the correct working directory (#187)
    • Fix problems with retrieving cache with parallel builds (#161, #152)
    • Fix problems restoring from cache on Windows (#79)

    1.3.0

    • Support passing --working-dir as part of composer-options

    1.2.0

    • Support Composer working-directory option for when composer.json is in a non-standard location.
    • Add operating system name to the cache key.

    1.1.0

    Display Composer output with ANSI colors.

    1.0.3

    Patch release for dependency updates.

    1.0.2

    • Use the GitHub cache action directly to avoid duplication of code/effort.
    • Turn on output of Composer command to provide feedback in the job log
    • Use Composer cache-dir instead of cache-files-dir

    1.0.1

    Rewrite and refactor as a JavaScript action.

    Commits
    • 83af392 :sparkles: Add new custom-cache-suffix option (#239)
    • 7f9021e Fix use of deprecated set-output command (#238)
    • 4617231 Tests: update the included composer.phar from v 2.2.2 to 2.2.18 (#237)
    • 72896eb Add dependabot configuration file (#227)
    • 69e970d GH Actions: version update for codecov action runner (#226)
    • e3612f6 GH Actions: version update for actions/cache (#224)
    • d515102 GH Actions: version update for various predefined actions (#222)
    • 6085843 GH Actions: re-work the integration tests (#221)
    • f680dac test: add PHP path back to command, as well as debug message
    • 3c51967 test: ensure we use the alternate composer location
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    opened by dependabot[bot] 1
  • Bump dependabot/fetch-metadata from 1.3.4 to 1.3.5

    Bump dependabot/fetch-metadata from 1.3.4 to 1.3.5

    Bumps dependabot/fetch-metadata from 1.3.4 to 1.3.5.

    Release notes

    Sourced from dependabot/fetch-metadata's releases.

    v1.3.5

    What's Changed

    New Contributors

    Full Changelog: https://github.com/dependabot/fetch-metadata/compare/v1...v1.3.5

    Commits
    • 5ef0018 Merge pull request #282 from dependabot/v1.3.5-release-notes
    • a9380d2 v1.3.5
    • 404ba25 Merge pull request #280 from dependabot/drop-readme-from-bump-script
    • f40d4c7 Don't bump pin versions in README.md
    • 7db64c3 Merge pull request #252 from dependabot/document-release-steps
    • daa85e7 Add mention of npm run build if dev deps need updating.
    • b768c40 Document steps for cutting a new release
    • 9833f74 Merge pull request #273 from dependabot/dependabot/npm_and_yarn/yargs-and-typ...
    • 32b7ed3 Bump yargs and @​types/yargs
    • 7942397 Merge pull request #271 from dependabot/dependabot/npm_and_yarn/actions/githu...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    opened by dependabot[bot] 1
  • Bump dependabot/fetch-metadata from 1.3.3 to 1.3.4

    Bump dependabot/fetch-metadata from 1.3.3 to 1.3.4

    Bumps dependabot/fetch-metadata from 1.3.3 to 1.3.4.

    Release notes

    Sourced from dependabot/fetch-metadata's releases.

    v1.3.4

    What's Changed

    New Contributors

    Full Changelog: https://github.com/dependabot/fetch-metadata/compare/v1.3.3...v1.3.4

    Commits
    • bfc19f4 v1.3.4
    • 4367f58 Merge pull request #258 from dependabot/dependabot/npm_and_yarn/yaml-2.1.1
    • 00ab600 Manually bump dist/
    • bdbe81d Bump yaml from 2.0.1 to 2.1.1
    • 5fc325a Merge pull request #257 from dependabot/dependabot/npm_and_yarn/typescript-4.8.3
    • c91309c Bump typescript from 4.6.3 to 4.8.3
    • 264d039 Merge pull request #266 from dependabot/dependabot/npm_and_yarn/ts-node-10.9.1
    • d1cd6ed Bump ts-node from 10.7.0 to 10.9.1
    • e3cb77e Merge pull request #265 from dependabot/dependabot/npm_and_yarn/actions/githu...
    • e462341 [dependabot skip] Update dist/ with build changes
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    opened by dependabot[bot] 1
  • Support notification mails

    Support notification mails

    As suggested in #27 and #29 this implements rendering notification's that use the toMail(): MailMessage method: laravel docs

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $url = url('/invoice/'.$this->invoice->id);
     
        return (new MailMessage)
                    ->greeting('Hello!')
                    ->line('One of your invoices has been paid!')
                    ->lineIf($this->amount > 0, "Amount paid: {$this->amount}")
                    ->action('View Invoice', $url)
                    ->line('Thank you for using our application!');
    }
    

    In order to support both Mailables and Notification's MailMessage I've refactored the way mailbook renders and collects all the data. Instead of rendering the mailable it is send to a custom mail driver/transport. This will not replace your current mail driver.

    Some things I need to finish:

    • [x] Update docs about notifications
    • [ ] Update docs about laravel version support (this PR will remove laravel 8 support_
    opened by Xammie 0
  • Remove refresh button

    Remove refresh button

    I have decided to remove the refresh button. This is because I feel like it adds no value and CMD + R is way faster. This also gives some more space in the top bar to add other features.

    opened by Xammie 0
  • Preview localization

    Preview localization

    This adds a new feature called preview localization.

    Screenshot 2022-10-21 at 17 10 22

    Using a config option you can define which locales your application uses. Within mailbook you will be able to select a language that you want to be used for the mail preview.

    enhancement 
    opened by Xammie 0
  • Use shadow root instead of iframe

    Use shadow root instead of iframe

    In order to keep the web page styling for bleeding into the email template we can use shadow root. The advantage is that this will only require 1 request instead of 2.

    opened by Xammie 0
  • UI improvements

    UI improvements

    • Improved background colors
    • Added a new sidebar with more information about the email
    • UI is cleaner and has less borders
    • Added size information
    • More responsive for smaller screens
    opened by Xammie 0
  • Fixed loading of mailables

    Fixed loading of mailables

    Instead of using require_once to load the route file once we keep track of whether or not the mailables have been loaded. This fixes an issue where if you where using mailbook in your tests it would only collect in the first test.

    opened by Xammie 0
  • Improved installation

    Improved installation

    This introduces a new way of installing mailbook using a install command.

    Routes will be loaded from a routes file instead of having to manually add a serviceprovider.

    opened by Xammie 0
Releases(1.5.0)
  • 1.5.0(Dec 22, 2022)

    What's Changed

    • Support notification mails by @Xammie in https://github.com/Xammie/mailbook/pull/30

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.4.1...1.5.0

    Source code(tar.gz)
    Source code(zip)
  • 1.4.1(Dec 20, 2022)

    What's Changed

    • Bump dependabot/fetch-metadata from 1.3.4 to 1.3.5 by @dependabot in https://github.com/Xammie/mailbook/pull/26
    • Bump ramsey/composer-install from 1 to 2 by @dependabot in https://github.com/Xammie/mailbook/pull/28
    • Fixed shrinking icons #31 by @Xammie in https://github.com/Xammie/mailbook/pull/32

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.4.0...1.4.1

    Source code(tar.gz)
    Source code(zip)
  • 1.4.0(Oct 26, 2022)

    What's Changed

    • Preview localization by @Xammie in https://github.com/Xammie/mailbook/pull/21
    • Remove refresh button by @Xammie in https://github.com/Xammie/mailbook/pull/22
    • Add extra details by @Xammie in https://github.com/Xammie/mailbook/pull/24
    • Support alternative mail syntax by @Xammie in https://github.com/Xammie/mailbook/pull/23

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.3.0...1.4.0

    Source code(tar.gz)
    Source code(zip)
  • 1.3.0(Oct 9, 2022)

    What's Changed

    • Improved mailables list by @Xammie in https://github.com/Xammie/mailbook/pull/20

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.2.0...1.3.0

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Oct 6, 2022)

    What's Changed

    • Laravel 8 support by @ItsRD in https://github.com/Xammie/mailbook/pull/19

    New Contributors

    • @ItsRD made their first contribution in https://github.com/Xammie/mailbook/pull/19

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Sep 22, 2022)

    What's Changed

    • Build assets in action by @Xammie in https://github.com/Xammie/mailbook/pull/12
    • Add option to disable credits by @Xammie in https://github.com/Xammie/mailbook/pull/14
    • Add reply to info by @Xammie in https://github.com/Xammie/mailbook/pull/15
    • Optimized closure calls by @Xammie in https://github.com/Xammie/mailbook/pull/16

    Full Changelog: https://github.com/Xammie/mailbook/compare/1.0.0...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Aug 26, 2022)

    First stable release of mailbook 🎉

    What's Changed

    • Attachments by @Xammie in https://github.com/Xammie/mailbook/pull/8
    • Added config option for changing the route file by @Xammie in https://github.com/Xammie/mailbook/pull/7
    • UI improvements by @Xammie in https://github.com/Xammie/mailbook/pull/9

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.9...1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.0.9(Aug 24, 2022)

    What's Changed

    • Fixed loading of mailables by @Xammie in https://github.com/Xammie/mailbook/pull/6

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.8...0.0.9

    Source code(tar.gz)
    Source code(zip)
  • 0.0.8(Aug 23, 2022)

    What's Changed

    • Improved installation by @Xammie in https://github.com/Xammie/mailbook/pull/5

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.7...0.0.8

    Source code(tar.gz)
    Source code(zip)
  • 0.0.7(Aug 8, 2022)

    What's Changed

    • Added config option to enable or disable routes by @Xammie in https://github.com/Xammie/mailbook/pull/4

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.6...0.0.7

    Source code(tar.gz)
    Source code(zip)
  • 0.0.6(Jul 22, 2022)

  • 0.0.5(Jul 22, 2022)

    What's Changed

    • Device preview by @Xammie in https://github.com/Xammie/mailbook/pull/3
    • Improved navigation layout
    • Added "Sent from" information

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.4...0.0.5

    Source code(tar.gz)
    Source code(zip)
  • 0.0.4(Jul 22, 2022)

    What's Changed

    • Fixed refresh button by @Xammie in https://github.com/Xammie/mailbook/pull/2

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.3...0.0.4

    Source code(tar.gz)
    Source code(zip)
  • 0.0.3(Jul 20, 2022)

    What's Changed

    • Variants by @Xammie in https://github.com/Xammie/mailbook/pull/1

    Full Changelog: https://github.com/Xammie/mailbook/compare/0.0.2...0.0.3

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Jul 11, 2022)

  • 0.0.1(Jul 7, 2022)

Owner
Max Hoogenbosch
Fullstack Developer at @Enrise
Max Hoogenbosch
A mail driver to quickly preview mail

A mail driver to quickly preview mail This package can display a small overlay whenever a mail is sent. The overlay contains a link to the mail that w

Spatie 1k Jan 4, 2023
Laravel Mail Credentials switcher for Budget Laravel Applications

Laravel Mail Switcher Laravel Mail Credentials Switcher is a library which helps you to: Manage your Mail Service Credentials Configure the Laravel's

(Seth) Phat Tran 34 Dec 24, 2022
Laravel Mail Catcher Driver

Laravel Mail Catcher Driver This package include a new mailbase driver which will catch all the sent emails and save it to the database. It then expos

Tauqeer Liaqat 94 Aug 30, 2022
Mail Web is a Laravel package which catches emails locally for debugging

Mail Web is a Laravel package which catches emails locally for debugging Installation Use the package manager composer to install Mail Web. composer r

Appoly 64 Dec 24, 2022
A testing package for intercepting mail sent from Laravel

Laravel Mail Intercept A testing package for intercepting mail sent from Laravel This testing suite intercepts Laravel Mail just before they are sent

Kirschbaum Development Group, LLC 91 Oct 18, 2022
Mandrill mail driver for Laravel for version 6+

Laravel Mandrill Driver This package re-enables Mandrill driver functionality using the Mail facade in Laravel 6+. To install the package in your proj

Eng Hasan Hajjar 2 Sep 30, 2022
Bounce Mail Handler for PHP | This is a "reboot" of PHPMailer-BMH from WorxWare.

PHP 7.0+ Support Composer & PSR-0 Support PHPUnit testing via Travis CI (TODO: more tests needed) PHP-Quality testing via SensioLabsInsight (TODO: mor

Lars Moelleken 43 Jan 7, 2023
:envelope: E-Mail Address Validator (syntax, dns, trash, typo)

✉️ E-Mail Address Validator for PHP Warning The best way to validate an e-mail address is still to send a duplicate opt-in-mail, when the user clicks

Lars Moelleken 41 Dec 25, 2022
Mail sending module for Mezzio and Laminas MVC with support for file attachment and template email composition

This module provides an easy and flexible way to send emails from Mezzio and Laminas MVC applications (formerly known as Zend Expressive and Zend MVC). It allows you to pre-configure emails and transports, and then send those emails at runtime.

null 82 Jan 16, 2022
PostfixAdmin - web based virtual user administration interface for Postfix mail servers

PostfixAdmin An open source, web based interface for managing domains/mailboxes/aliases etc on a Postfix based mail server.

PostfixAdmin 755 Jan 3, 2023
Provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice

WP PHPMailer provides a clean and simple way to configure the WordPress-bundled PHPMailer library, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Itineris Limited 61 Dec 6, 2022
💌 Mail app for Nextcloud

Nextcloud Mail ?? A mail app for Nextcloud Why is this so awesome? ?? Integration with other Nextcloud apps! Currently Contacts, Calendar & Files – mo

Nextcloud 684 Dec 26, 2022
Crud PHP 8 com Form E-mail

Crud com PHP 8 PDO Login - Cadastro de Usuários - Edição - Deleção - Adição | Formulário envio de e-mail Para rodar o Crud é preciso instalar um servi

Isaias Oliveira 4 Nov 16, 2021
Simple mail sending by PHPMailer and Create your local system.

Simple mail sending by PHPMailer and Create your local system. Send mail zero of cost and also send Attachment like Photo, pdf and multiple files. You should be create a login and verify two steps authentication like OTP, verifications ?? link. PHPMailer make your dreams project eassy and simple also free of cost.

SUSHIL KUMBHAR 2 Dec 8, 2021
Mail application developed with Symfony 5

Fakey-Mail Mail application developed with Symfony 5! Check out the requirements for info on how to launch the app. Check out the basic functionality

Mauro 2 Jun 21, 2022
Mail Api for fetch or send mails

flux-mail-api Mail Api for fetch or send mails Installation Native Download RUN (mkdir -p /%path%/libs/flux-mail-api && cd /%path%/libs/flux-mail-api

null 2 Dec 12, 2022
Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app.

Laravel IMAP is an easy way to integrate both the native php-imap module and an extended custom imap protocol into your Laravel app. This enables your app to not only respond to new emails but also allows it to read and parse existing mails and much more.

null 530 Jan 6, 2023
MailEclipse - Laravel Mailable Editor!

MailEclipse is a mailable editor package for your Laravel applications to create and manage mailables using a web UI.

Yassine Qoraiche 1.9k Jan 5, 2023
Offer an online version of your Laravel emails to users.

This is was a collaborative project with Ryan Chandler. Please consider supporting him for the hard work he put into this package! Help support the ma

Sam Carré 251 Dec 25, 2022