Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
axyr committed Jul 4, 2024
1 parent 5f557e5 commit 8c59bfc
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 17 deletions.
1 change: 0 additions & 1 deletion .gitbook.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
root: ./docs/
structure:
readme: ./../README.md
summary: ./SUMMARY.md
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ an email driver for your local or staging environment, you can inspect emails wi
* Packed with a simple Blade UI and a Vue.js/JSON controller
* Easily integrate in your existing application

## Usage

Outgoing emails will be automatically copied to a local disk or table, but you can work with this package manually as well with the Emails facade:

```php
<?php
use Axyr\EmailViewer\Facades\Emails;

Emails::create($mimeMessage);
Emails::find($fileNameOrId);
Emails::delete($fileNameOrId);
Emails::paginate(10);
Emails::prune();
Emails::server('database')->get();
```

## Quick start

Run the composer install command from the terminal:
Expand All @@ -29,7 +45,7 @@ composer require axyr/laravel-email-viewer
Publish the database migration and configuration file:

```php
php artisan vendor:publish --provider="Axyr\EmailViewer\EmailViewerServiceProvider"
php artisan vendor:publish --provider="Axyr\EmailViewer\EmailViewerServiceProvider"
```

By default the package provides a set of routes for the Blade UI and the Vue UI. You can disabled them in the config file.
Expand All @@ -40,10 +56,11 @@ You can access the Blade UI by visiting:
https://your-host.tld/emails
```

To send a test email the package provides a Test command:
To send a test email the package provides a simple Test command.
By default it will send to the laraval config value `mail.from.address`

```php
php artisan email-viewer:send-test
php artisan email-viewer:send-test [email protected] [email protected]
```

For further information and customisation, visit our documentation page:
Expand Down
42 changes: 41 additions & 1 deletion config/emailviewer.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
<?php

return [
/*
* This option defines the default storage method.
* You can choose between one of the Laravel
* filesystem disks or a database table.
*/
'default' => env('EMAIL_VIEWER_DEFAULT', 'disk'),

/*
* When this option is set to false, the package will not copy any emails.
*/
'enabled' => (bool)env('EMAIL_VIEWER_ENABLED', true),

/*
* The PhpMimeMailParser uses the pecl mailparse extension.
* Replace this class if you want to use a customer mail parser.
*/
'parser' => \Axyr\EmailViewer\Parsers\PhpMimeMailParser::class,

/*
* The EmailWriterListener listens to the MessageSending event
* and copies the email to the default storage.
*/
'listener' => \Axyr\EmailViewer\Listeners\EmailWriterListener::class,

/*
* Disable this setting, if you don't want to use the default routes
* and instead use your own route setup.
*/
'routes-enabled' => true,
'route-namespace' => 'emails',

/*
* If you do want to use the default routes,
* but want a different prefix, you can adjust this value.
*/
'route-prefix' => 'emails',

/*
* The package controllers default items per page for the pagination results.
* If you want to use the shipped controllers, but a different default items per page,
* change this value.
*/
'default_pagination' => 25,

/*
* The possible 'servers' where you can store a copy of all the outgoing emails.
* You can swap out the model and repository classes with your own implementations.
*/
'servers' => [
'disk' => [
'disk_name' => env('EMAIL_VIEWER_DISK', env('FILESYSTEM_DISK', 'local')),
Expand Down
66 changes: 66 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
# Configuration

```php
<?php

return [
/*
* This option defines the default storage method.
* You can choose between one of the Laravel
* filesystem disks or a database table.
*/
'default' => env('EMAIL_VIEWER_DEFAULT', 'disk'),

/*
* When this option is set to false, the package will not copy any emails.
*/
'enabled' => (bool)env('EMAIL_VIEWER_ENABLED', true),

/*
* The PhpMimeMailParser uses the pecl mailparse extension.
* Replace this class if you want to use a customer mail parser.
*/
'parser' => \Axyr\EmailViewer\Parsers\PhpMimeMailParser::class,

/*
* The EmailWriterListener listens to the MessageSending event
* and copies the email to the default storage.
*/
'listener' => \Axyr\EmailViewer\Listeners\EmailWriterListener::class,

/*
* Disable this setting, if you don't want to use the default routes
* and instead use your own route setup.
*/
'routes-enabled' => true,

/*
* If you do want to use the default routes,
* but want a different prefix, you can adjust this value.
*/
'route-prefix' => 'emails',

/*
* The package controllers default items per page for the pagination results.
* If you want to use the shipped controllers, but a different default items per page,
* change this value.
*/
'default_pagination' => 25,

/*
* The possible 'servers' where you can store a copy of all the outgoing emails.
* You can swap out the model and repository classes with your own implementations.
*/
'servers' => [
'disk' => [
'disk_name' => env('EMAIL_VIEWER_DISK', env('FILESYSTEM_DISK', 'local')),
'model' => \Axyr\EmailViewer\Servers\Disk\Email::class,
'repository' => \Axyr\EmailViewer\Servers\Disk\Repository::class,
],
'database' => [
'table_name' => 'email_viewer_emails',
'model' => \Axyr\EmailViewer\Servers\Database\Email::class,
'repository' => \Axyr\EmailViewer\Servers\Database\Repository::class,
],
],
];
```
27 changes: 27 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# Installation

Run the composer install command from the terminal:

```php
composer require axyr/laravel-email-viewer
```

Publish the database migration and configuration file:

```php
php artisan vendor:publish --provider="Axyr\EmailViewer\EmailViewerServiceProvider"
```

By default the package provides a set of routes for the Blade UI and the Vue UI. You can disabled them in the config file.

You can access the Blade UI by visiting:

```
https://your-host.tld/emails
```

To send a test email the package provides a simple Test command.
By default it will send to the laraval config value `mail.from.address`

```php
php artisan email-viewer:send-test [email protected] [email protected]
```
17 changes: 17 additions & 0 deletions docs/laravel-email-viewer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 📨 Laravel Email Viewer

View and inspect all emails sent from your Laravel application.

![](docs/img/mailboxes.png)

Laravel Email Viewer is a package that allows you to view all emails sent from you application in the browser. This allows you to ensure your application has actually sent the mail. When using log as
an email driver for your local or staging environment, you can inspect emails without the need for external tools like Mailtrap or Mailhog, so emails never have to leave your server at all.

[![Latest Version on Packagist](https://img.shields.io/packagist/v/axyr/laravel-email-viewer.svg?style=flat-square)](https://packagist.org/packages/axyr/laravel-email-viewer) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-permission/run-tests-L8.yml?branch=main\&label=Tests)](https://github.com/axyr/laravel-email-viewer/actions?query=workflow%3ATests+branch%3Amain)

## Key features

* Log all application emails to a storage disk or database table
* Inspect HTML, attachments and email headers
* Packed with a simple Blade UI and a Vue.js/JSON controller
* Easily integrate in your existing application
2 changes: 2 additions & 0 deletions docs/requirements.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Requirements

mailparse
2 changes: 1 addition & 1 deletion resources/views/layout/sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/** @var \Axyr\EmailViewer\Contracts\EmailMessage $email */
$routeNamespace = config('emailviewer.route-namespace')
$routeNamespace = config('emailviewer.route-prefix')
?>
@foreach($emails as $email)
<a href="{{ route($routeNamespace . '.show', $email->id()) }}">
Expand Down
14 changes: 7 additions & 7 deletions routes/emailviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
use Axyr\EmailViewer\Http\Controllers\JsonEmailController;
use Illuminate\Support\Facades\Route;

$routeNamespace = config('emailviewer.route-namespace');
$routePrefix = config('emailviewer.route-prefix');

Route::get($routeNamespace . '/json', [JsonEmailController::class, 'index'])->name($routeNamespace . '.json.index');
Route::get($routeNamespace . '/{id}/json', [JsonEmailController::class, 'show'])->name($routeNamespace . '.json.show');
Route::delete($routeNamespace . '/{id}/json', [JsonEmailController::class, 'destroy'])->name($routeNamespace . '.json.destroy');
Route::get($routePrefix . '/json', [JsonEmailController::class, 'index'])->name($routePrefix . '.json.index');
Route::get($routePrefix . '/{id}/json', [JsonEmailController::class, 'show'])->name($routePrefix . '.json.show');
Route::delete($routePrefix . '/{id}/json', [JsonEmailController::class, 'destroy'])->name($routePrefix . '.json.destroy');

Route::get($routeNamespace, [BladeEmailController::class, 'index'])->name($routeNamespace . '.index');
Route::get($routeNamespace . '/{id}', [BladeEmailController::class, 'show'])->name($routeNamespace . '.show');
Route::delete($routeNamespace . '/{id}', [BladeEmailController::class, 'destroy'])->name($routeNamespace . '.destroy');
Route::get($routePrefix, [BladeEmailController::class, 'index'])->name($routePrefix . '.index');
Route::get($routePrefix . '/{id}', [BladeEmailController::class, 'show'])->name($routePrefix . '.show');
Route::delete($routePrefix . '/{id}', [BladeEmailController::class, 'destroy'])->name($routePrefix . '.destroy');
2 changes: 1 addition & 1 deletion src/Http/Controllers/BladeEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function destroy(string|int $id): RedirectResponse
{
Emails::delete($id);

$routeNamespace = config('emailviewer.route-namespace');
$routeNamespace = config('emailviewer.route-prefix');

return redirect(route($routeNamespace . '.index'));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Http/Controllers/JsonEmailControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testListsPaginatedEmails(): void
{
config()->set('emailviewer.default_pagination', 3);

$routeNamespace = config('emailviewer.route-namespace');
$routeNamespace = config('emailviewer.route-prefix');

for ($i = 0; $i < 6; $i++) {
app(Repository::class)->create($this->emailContent . $i);
Expand All @@ -41,7 +41,7 @@ public function testListsPaginatedEmails(): void

public function testShowsAnEmail(): void
{
$routeNamespace = config('emailviewer.route-namespace');
$routeNamespace = config('emailviewer.route-prefix');

$email = app(Repository::class)->create($this->emailContent);

Expand All @@ -52,7 +52,7 @@ public function testShowsAnEmail(): void

public function testDeletesAnEmail(): void
{
$routeNamespace = config('emailviewer.route-namespace');
$routeNamespace = config('emailviewer.route-prefix');

$email = app(Repository::class)->create($this->emailContent);

Expand Down

0 comments on commit 8c59bfc

Please sign in to comment.