Catch outgoing mail during local development and read it in the browser at /mail. Set MAIL_MAILER=lens and every email your Laravel app sends is stored instead of delivered.
hexters/maillens is a Laravel package for catch outgoing mail during local development and read it in the browser at /mail. set mail_mailer=lens and every email your laravel app sends is stored instead of delivered..
It currently has 7 GitHub stars and 320 downloads on Packagist (latest version 1.3.2).
Install it with composer require hexters/maillens.
Discover more Laravel packages by hexters
or browse all Laravel packages to compare alternatives.
Last updated
MailLens catches the email your app sends while you are developing, so you can
read it in the browser instead of wiring up a real inbox. Set one env variable
and every message your Laravel app tries to send gets saved and shown at
/mail. There is nothing to install outside Composer, no Docker, and no SMTP
catcher running in the background.
If you have used Mailtrap or Mailpit before, it is the same idea, except it lives inside your own app.
composer require hexters/maillens --dev
Run the migration to create the table MailLens stores mail in:
php artisan migrate
Then point the mailer at MailLens in your .env:
MAIL_MAILER=lens
Now send mail the way you normally would and open /mail to read it. You do not
need to touch config/mail.php; MailLens adds the lens mailer for you.
Setting MAIL_MAILER=lens sends your mail through a transport that stores the
message instead of delivering it. It keeps the subject, the sender and
recipients, the HTML and text bodies, any attachments, and the raw source. The
/mail page puts the message list on one side and the selected message on the
other, with tabs for HTML, plain text, and source, plus links to download any
attachments.
MailLens only changes where your mail ends up, not how your queue works. If a
mailable is queued (ShouldQueue, Mail::queue(), or a queued notification),
it shows up in /mail after the queue runs the job, the same as it would before
a real send:
QUEUE_CONNECTION=database: run a worker with php artisan queue:workQUEUE_CONNECTION=redis: run your worker, or Horizon if that is your setupQUEUE_CONNECTION=sync: nothing to run, the mail is captured right awaySo if a queued email never shows up, check that a worker is running before you blame MailLens.
There is no separate switch. MAIL_MAILER is the switch. When it is set to
anything other than lens, MailLens stays quiet: it does not register the
/mail route and nothing routes through it. Keep MAIL_MAILER=lens out of your
production .env and your mail will send for real there.
By default /mail is open, which is fine on your own machine. If the inbox
lives somewhere other people can reach, such as a shared staging server, set a
password and MailLens asks for it before showing anything:
MAILLENS_PASSWORD=some-secret
Leave it unset and there is no lock screen.
Most people never need this, but you can publish the config file to change the defaults:
php artisan vendor:publish --tag=maillens-config
MAILLENS_PASSWORD= # protect /mail with a password (unset = open)
MAILLENS_ROUTE_PREFIX=mail # the inbox lives here
MAILLENS_LIMIT=200 # how many messages to keep (null keeps all of them)
Captured mail is saved on your app's default database connection.
Bug reports and pull requests are welcome. Have a look at CONTRIBUTING.md first.
MIT. See LICENSE.