├── .github ├── FUNDING.yml └── workflows │ └── php.yml ├── .gitignore ├── .phpunit.cache └── test-results ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── sentemails.php ├── phpunit.xml ├── pint.json ├── src ├── Controllers │ └── SentEmailsController.php ├── Listeners │ └── EmailLogger.php ├── Models │ ├── SentEmail.php │ └── SentEmailAttachment.php ├── SentEmailsServiceProvider.php ├── database │ ├── factories │ │ ├── SentEmailAttachmentFactory.php │ │ └── SentEmailFactory.php │ └── migrations │ │ ├── 2020_07_16_222057_create_sent_emails_table.php │ │ ├── 2024_05_07_204307_change_body_lengh.php │ │ └── 2024_05_07_222057_create_sent_emails_attachments_table.php ├── resources │ └── views │ │ ├── email.blade.php │ │ ├── index.blade.php │ │ └── pagination.blade.php └── routes │ └── web.php └── tests ├── Pest.php ├── SentEmailsTest.php └── TestCase.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [dcblogdev] 4 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Pipeline 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | strategy: 11 | max-parallel: 2 12 | matrix: 13 | php-versions: ['8.1', '8.2', '8.3'] 14 | 15 | name: PHP ${{ matrix.php-versions }} 16 | 17 | steps: 18 | - uses: actions/checkout@v1 19 | 20 | - name: Setup PHP 21 | uses: shivammathur/setup-php@master 22 | with: 23 | php-version: ${{ matrix.php-versions }} 24 | coverage: xdebug 25 | 26 | - name: Validate composer.json and composer.lock 27 | run: composer validate 28 | 29 | - name: Install dependencies 30 | run: composer install --prefer-dist --no-progress --no-suggest 31 | 32 | - name: Run Pint 33 | run: ./vendor/bin/pint --test 34 | 35 | - name: Run test suite 36 | run: ./vendor/bin/pest --parallel 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | vendor 3 | .idea 4 | .phpunit.result.cache 5 | .phpunit.cache 6 | phpunit.xml.bak 7 | test-results.DS_Store 8 | -------------------------------------------------------------------------------- /.phpunit.cache/test-results: -------------------------------------------------------------------------------- 1 | {"version":"pest_2.34.7","defects":[],"times":{"P\\Tests\\SentEmailsTest::__pest_evaluable_can_see_emails_inbox":0.138,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_see_email":0.014,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_see_email_body":0.013,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_download_attachment":0.007,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_filter_emails":0.016,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_filter_emails_by_date":0.015,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_filter_emails_by_from":0.014,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_filter_emails_by_to":0.014,"P\\Tests\\SentEmailsTest::__pest_evaluable_can_filter_emails_by_subject":0.014}} -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) dcblogdev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Community 2 | 3 | There is a Discord community. https://discord.gg/VYau8hgwrm For quick help, ask questions in the appropriate channel. 4 | 5 | # Record and view all sent emails 6 | 7 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/dcblogdev/laravel-sent-emails.svg?style=flat-square)](https://packagist.org/packages/dcblogdev/laravel-sent-emails) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/dcblogdev/laravel-sent-emails.svg?style=flat-square)](https://packagist.org/packages/dcblogdev/laravel-sent-emails) 9 | 10 | ![Example UI](https://repository-images.githubusercontent.com/279137838/610e3200-1d0e-11eb-8a39-7812708a55cd) 11 | 12 | Watch a video walkthrough https://www.youtube.com/watch?v=Oj_OF5n4l4k&feature=youtu.be 13 | 14 | ![Sample UI](https://user-images.githubusercontent.com/1018170/107695686-d80d7c00-6ca8-11eb-8a49-c08ddfa701fb.png) 15 | 16 | ## Installation 17 | 18 | > Note version 2+ requires Laravel 9+ 19 | 20 | You can install the package via composer: 21 | 22 | ``` 23 | composer require dcblogdev/laravel-sent-emails 24 | ``` 25 | 26 | ## Migration 27 | 28 | You can publish the migration with: 29 | 30 | ``` 31 | php artisan vendor:publish --provider="Dcblogdev\LaravelSentEmails\SentEmailsServiceProvider" --tag="migrations" 32 | ``` 33 | 34 | After the migration has been published you can the tables by running the migration: 35 | 36 | ``` 37 | php artisan migrate 38 | ``` 39 | 40 | ## Config 41 | 42 | You can publish the config with: 43 | 44 | ``` 45 | php artisan vendor:publish --provider="Dcblogdev\LaravelSentEmails\SentEmailsServiceProvider" --tag="config" 46 | ``` 47 | 48 | After the config has been published you can change the route path for sentemails from /sentemails to anything you like such as /admin/sentemails: 49 | 50 | ``` 51 | 'routepath' => 'sentemails' 52 | ``` 53 | 54 | ### ENV variables 55 | 56 | ```php 57 | SENT_EMAILS_ROUTE_PATH=admin/sentemails 58 | SENT_EMAILS_PER_PAGE=10 59 | SENT_EMAILS_STORE_EMAILS=true 60 | SENT_EMAILS_NO_EMAILS_MESSAGE='No emails have been sent' 61 | SENT_EMAILS_COMPRESS_BODY=true 62 | ``` 63 | 64 | ## Views 65 | You can publish the view with: 66 | 67 | ``` 68 | php artisan vendor:publish --provider="Dcblogdev\LaravelSentEmails\SentEmailsServiceProvider" --tag="views" 69 | ``` 70 | 71 | The views will be published to resources/views/vendor/sentemails 72 | 73 | You can change the views to match your theme if desired. 74 | 75 | ## Usage 76 | 77 | As soon as an email is sent it will be added to a database table and will be viewable in /sentemails. 78 | 79 | > Note you have to be logged in to be able to see /sentemails, if you are not logged in when you attempt to see /sentemails you will be redirected to a login route. 80 | 81 | ### Changelog 82 | 83 | Please see [Releases](https://github.com/dcblogdev/laravel-sent-emails/releases) for more information what has changed recently. 84 | 85 | ## Contributing 86 | 87 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 88 | 89 | ### Security 90 | 91 | If you discover any security related issues, please email dave@dcblog.dev instead of using the issue tracker. 92 | 93 | ## Credits 94 | 95 | - [David Carr](https://github.com/dcblogdev) 96 | - [All Contributors](../../contributors) 97 | 98 | ## License 99 | 100 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 101 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dcblogdev/laravel-sent-emails", 3 | "description": "Store outgoing emails in Laravel", 4 | "keywords": [ 5 | "dcblogdev", 6 | "laravel", 7 | "sent-emails" 8 | ], 9 | "homepage": "https://github.com/dcblogdev/laravel-sent-emails", 10 | "license": "MIT", 11 | "type": "library", 12 | "authors": [ 13 | { 14 | "name": "David Carr", 15 | "email": "dave@dcblog.dev", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "illuminate/support": "9.x|10.x|11.x|^12.0", 21 | "ext-zlib": "*", 22 | "doctrine/dbal": "^3.8|^4.2" 23 | }, 24 | "require-dev": { 25 | "pestphp/pest": "^2.0|^3.7", 26 | "orchestra/testbench": "^8.22|^10.0", 27 | "laravel/pint": "^1.15" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "Dcblogdev\\LaravelSentEmails\\": "src", 32 | "Dcblogdev\\LaravelSentEmails\\Tests\\": "tests" 33 | } 34 | }, 35 | "autoload-dev": { 36 | "classmap": [ 37 | "tests/TestCase.php" 38 | ] 39 | }, 40 | "scripts": { 41 | "lint": "./vendor/bin/pint", 42 | "test": "./vendor/bin/pest", 43 | "check": [ 44 | "@lint", 45 | "@test" 46 | ] 47 | }, 48 | "extra": { 49 | "laravel": { 50 | "providers": [ 51 | "Dcblogdev\\LaravelSentEmails\\SentEmailsServiceProvider" 52 | ] 53 | } 54 | }, 55 | "config": { 56 | "allow-plugins": { 57 | "pestphp/pest-plugin": true 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /config/sentemails.php: -------------------------------------------------------------------------------- 1 | env('SENT_EMAILS_ROUTE_PATH', 'sentemails'), 9 | 10 | // set the route middlewares to apply on the sent emails ui 11 | 'middleware' => ['web', 'auth'], 12 | 13 | // emails per page 14 | 'perPage' => env('SENT_EMAILS_PER_PAGE', 10), 15 | 16 | 'storeAttachments' => env('SENT_EMAILS_STORE_EMAIL', true), 17 | 18 | 'noEmailsMessage' => env('SENT_EMAILS_NO_EMAILS_MESSAGE', 'No emails found.'), 19 | 20 | // body emails are stored as compressed strings to save db disk 21 | /* Do not change after first mail is stored */ 22 | 'compressBody' => env('SENT_EMAILS_COMPRESS_BODY', false), 23 | ]; 24 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./tests 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | src/ 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /pint.json: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "laravel" 3 | } -------------------------------------------------------------------------------- /src/Controllers/SentEmailsController.php: -------------------------------------------------------------------------------- 1 | orderby('id', 'desc') 16 | ->applyFilters($request) 17 | ->paginate(config('sentemails.perPage')); 18 | 19 | return view('sentemails::index', compact('emails')); 20 | } 21 | 22 | public function email(string $id): View 23 | { 24 | $email = SentEmail::findOrFail($id); 25 | 26 | return view('sentemails::email', compact('email')); 27 | } 28 | 29 | public function body(string $id): string 30 | { 31 | $email = SentEmail::findOrFail($id); 32 | 33 | return $email->body; 34 | } 35 | 36 | public function downloadAttachment(string $id): BinaryFileResponse 37 | { 38 | $attachment = SentEmailAttachment::findOrFail($id); 39 | 40 | return response()->download(storage_path('app/'.$attachment->path), $attachment->filename); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Listeners/EmailLogger.php: -------------------------------------------------------------------------------- 1 | message; 15 | $body = $message->getHtmlBody() ?: $message->getTextBody() ?: ''; 16 | $email = SentEmail::create([ 17 | 'date' => date('Y-m-d H:i:s'), 18 | 'from' => $this->formatAddressField($message->getFrom()), 19 | 'to' => $this->formatAddressField($message->getTo()), 20 | 'cc' => $this->formatAddressField($message->getCc()), 21 | 'bcc' => $this->formatAddressField($message->getBcc()), 22 | 'subject' => $message->getSubject(), 23 | 'body' => $body, 24 | ]); 25 | 26 | if (config('sentemails.storeAttachments')) { 27 | foreach ($message->getAttachments() as $attachment) { 28 | 29 | $path = 'sent-emails/'.now().'-'.$attachment->getFilename(); 30 | Storage::disk('local')->put($path, $attachment->getBody()); 31 | 32 | SentEmailAttachment::create([ 33 | 'sent_email_id' => $email->id, 34 | 'filename' => $attachment->getFilename(), 35 | 'path' => $path, 36 | ]); 37 | } 38 | } 39 | } 40 | 41 | public function formatAddressField(array $field): ?string 42 | { 43 | $strings = []; 44 | 45 | foreach ($field as $row) { 46 | $email = $row->getAddress(); 47 | $name = $row->getName(); 48 | 49 | if ($name != '') { 50 | $email = $name.' <'.$email.'>'; 51 | } 52 | 53 | $strings[] = $email; 54 | } 55 | 56 | return implode(', ', $strings); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Models/SentEmail.php: -------------------------------------------------------------------------------- 1 | attributes['body'] = $body; 44 | } 45 | 46 | public function attachments(): HasMany 47 | { 48 | return $this->hasMany(SentEmailAttachment::class); 49 | } 50 | 51 | public function scopeApplyFilters($query, Request $request) 52 | { 53 | $date = $request->input('date'); 54 | $from = $request->input('from'); 55 | $to = $request->input('to'); 56 | $subject = $request->input('subject'); 57 | 58 | $query->when($date, function ($query, $date) { 59 | $query->where('date', '=', Carbon::parse($date)->format('Y-m-d')); 60 | }) 61 | ->when($from, function ($query, $from) { 62 | $query->where('from', 'like', "%$from%"); 63 | }) 64 | ->when($to, function ($query, $to) { 65 | $query->where('to', 'like', "%$to%"); 66 | }) 67 | ->when($subject, function ($query, $subject) { 68 | $query->where('subject', 'like', "%$subject%"); 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Models/SentEmailAttachment.php: -------------------------------------------------------------------------------- 1 | loadViewsFrom(__DIR__.'/resources/views', 'sentemails'); 20 | $this->loadRoutesFrom(__DIR__.'/routes/web.php'); 21 | 22 | if ($this->app->runningUnitTests()) { 23 | $this->loadMigrationsFrom(__DIR__.'/database/migrations'); 24 | } 25 | 26 | if ($this->app->runningInConsole()) { 27 | 28 | $this->publishes([ 29 | __DIR__.'/../config/sentemails.php' => config_path('sentemails.php'), 30 | ], 'config'); 31 | 32 | $this->publishes([ 33 | __DIR__.'/database/migrations/2020_07_16_222057_create_sent_emails_table.php' => $this->app->databasePath().'/migrations/2020_07_16_222057_create_sent_emails_table.php', 34 | __DIR__.'/database/migrations/2024_05_07_204307_change_body_lengh.php' => $this->app->databasePath().'/migrations/2024_05_07_204307_change_body_lengh.php', 35 | __DIR__.'/database/migrations/2024_05_07_222057_create_sent_emails_attachments_table.php' => $this->app->databasePath().'/migrations/2024_05_07_222057_create_sent_emails_attachments_table.php', 36 | ], 'migrations'); 37 | 38 | $this->publishes([ 39 | __DIR__.'/resources/views' => resource_path('views/vendor/sentemails'), 40 | ], 'views'); 41 | } 42 | } 43 | 44 | public function register(): void 45 | { 46 | $this->mergeConfigFrom(__DIR__.'/../config/sentemails.php', 'sentemails'); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/database/factories/SentEmailAttachmentFactory.php: -------------------------------------------------------------------------------- 1 | SentEmail::factory(), 18 | 'filename' => Str::random(10).'.txt', 19 | 'path' => 'sent-emails/'.Str::random(10).'.txt', 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/database/factories/SentEmailFactory.php: -------------------------------------------------------------------------------- 1 | date('Y-m-d H:i:s'), 16 | 'from' => fake()->email, 17 | 'to' => fake()->email, 18 | 'cc' => fake()->email, 19 | 'bcc' => fake()->email, 20 | 'subject' => fake()->sentence, 21 | 'body' => fake()->realText, 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/database/migrations/2020_07_16_222057_create_sent_emails_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->date('date')->nullable(); 19 | $table->string('from')->nullable(); 20 | $table->text('to')->nullable(); 21 | $table->text('cc')->nullable(); 22 | $table->text('bcc')->nullable(); 23 | $table->string('subject')->nullable(); 24 | $table->text('body'); 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('sent_emails'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /src/database/migrations/2024_05_07_204307_change_body_lengh.php: -------------------------------------------------------------------------------- 1 | longText('body')->change(); 16 | }); 17 | } 18 | 19 | /** 20 | * Reverse the migrations. 21 | */ 22 | public function down(): void 23 | { 24 | Schema::table('sent_emails', function (Blueprint $table) { 25 | $table->text('body')->change(); 26 | }); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/database/migrations/2024_05_07_222057_create_sent_emails_attachments_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 14 | $table->foreignIdFor(SentEmail::class)->nullable(); 15 | $table->string('filename')->nullable(); 16 | $table->text('path')->nullable(); 17 | $table->timestamps(); 18 | }); 19 | } 20 | 21 | public function down(): void 22 | { 23 | Schema::dropIfExists('sent_emails_attachments'); 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /src/resources/views/email.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

{{ $email->subject }}

4 |
5 | #{{ $email->id }} 6 |
7 |
8 |
9 |
10 | 11 |
12 |
13 |

14 | 15 | {{ $email->from }}
16 | {{ __('To') }}: {{ $email->to }}
17 | @if ($email->cc !=''){{ __('CC') }}: {{ $email->cc }}
@endif 18 | @if ($email->bcc !=''){{ __('BCC') }}: {{ $email->bcc }}
@endif 19 | @if (config('sentemails.storeAttachments')) 20 | @if ($email->attachments->count() > 0) 21 | {{ __('Attachment') }} 22 | @endif 23 | @foreach($email->attachments as $attachment) 24 | 27 | {{ $attachment->filename }} 28 | 29 | @endforeach 30 | @endif 31 |
32 |

33 |
34 | {{ date('F jS Y H:i A', strtotime($email->created_at)) }} 35 |
36 |
37 |
38 | 39 |
40 |
41 | 42 |
-------------------------------------------------------------------------------- /src/resources/views/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ __('Sent Emails') }} 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 | {{ __('Sent Emails') }} 14 |
15 |
16 | 17 |
18 |
19 | 20 |
21 | 22 |
23 | 24 |
25 | 26 |
27 | 28 |
29 |
30 | 31 |
32 | 33 |
34 | 35 |
36 |
37 | 38 |
39 | 40 |
41 | 42 |
43 |
44 | 45 |
46 | 47 |
48 | 49 |
50 |
51 | 52 |
53 |
54 | 55 | Reset 56 |
57 |
58 | 59 |
60 | 61 |
62 | 63 |
64 |
65 | 66 | 67 | 68 |
69 | 70 |
71 | 72 |
73 |
74 | @foreach($emails as $email) 75 | @php 76 | $parts = explode('<', $email->from); 77 | if (isset($parts[1])) { 78 | $from = $parts[0]; 79 | } else { 80 | $from = $parts[0]; 81 | } 82 | @endphp 83 | 84 |
85 | {{ $from }} 86 | {{ $email->created_at->diffForHumans() }} 87 |
88 |

{{ $email->subject }}

89 | @if(config('sentemails.storeAttachments')) 90 | {{ __('Attachments') }}: {{ $email->attachments->count() }} 91 | @endif 92 |
93 | @endforeach 94 |
95 |
96 | 97 |
98 |
99 |
100 | 101 |
102 | 103 |
104 | 105 | @if ($emails->count() == 0) 106 |
107 |

{{ config('sentemails.noEmailsMessage') }}

108 |
109 | @endif 110 | 111 | {{ $emails->links('sentemails::pagination') }} 112 | 113 | -------------------------------------------------------------------------------- /src/resources/views/pagination.blade.php: -------------------------------------------------------------------------------- 1 | @if ($paginator->hasPages()) 2 | 102 | @endif -------------------------------------------------------------------------------- /src/routes/web.php: -------------------------------------------------------------------------------- 1 | group(function () { 7 | Route::get(config('sentemails.routepath'), [SentEmailsController::class, 'index'])->name('sentemails.index'); 8 | Route::get(config('sentemails.routepath').'/email/{id}', [SentEmailsController::class, 'email'])->name('sentemails.email'); 9 | Route::get(config('sentemails.routepath').'/body/{id}', [SentEmailsController::class, 'body'])->name('sentemails.body'); 10 | Route::get(config('sentemails.routepath').'/attachment-{id}', [SentEmailsController::class, 'downloadAttachment'])->name('sentemails.downloadAttachment'); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/Pest.php: -------------------------------------------------------------------------------- 1 | in(__DIR__); 6 | -------------------------------------------------------------------------------- /tests/SentEmailsTest.php: -------------------------------------------------------------------------------- 1 | count(10)->create(); 8 | $this->get(route('sentemails.index')) 9 | ->assertOk() 10 | ->assertViewHas('emails', function ($emails) { 11 | return $emails->count() === 10; 12 | } 13 | ); 14 | }); 15 | 16 | test('can filter emails by date', function () { 17 | 18 | SentEmail::factory()->create(['date' => '2023-10-20']); 19 | SentEmail::factory()->create(['date' => '2023-10-20']); 20 | SentEmail::factory()->create(); 21 | 22 | $this->get(route('sentemails.index', ['date' => '2023-10-20'])) 23 | ->assertOk() 24 | ->assertViewHas('emails', function ($emails) { 25 | return $emails->count() === 2; 26 | } 27 | ); 28 | }); 29 | 30 | test('can filter emails by from', function () { 31 | 32 | SentEmail::factory()->create(['from' => 'demo@demo.com']); 33 | SentEmail::factory()->create(); 34 | 35 | $this->get(route('sentemails.index', ['from' => 'demo@demo.com'])) 36 | ->assertOk() 37 | ->assertViewHas('emails', function ($emails) { 38 | return $emails->count() === 1; 39 | } 40 | ); 41 | }); 42 | 43 | test('can filter emails by to', function () { 44 | 45 | SentEmail::factory()->create(['to' => 'demo@demo.com']); 46 | SentEmail::factory()->create(); 47 | 48 | $this->get(route('sentemails.index', ['to' => 'demo@demo.com'])) 49 | ->assertOk() 50 | ->assertViewHas('emails', function ($emails) { 51 | return $emails->count() === 1; 52 | } 53 | ); 54 | }); 55 | 56 | test('can filter emails by subject', function () { 57 | 58 | SentEmail::factory()->create(['subject' => 'Demo']); 59 | SentEmail::factory()->create(['subject' => 'Other']); 60 | 61 | $this->get(route('sentemails.index', ['subject' => 'Demo'])) 62 | ->assertOk() 63 | ->assertViewHas('emails', function ($emails) { 64 | return $emails->count() === 1; 65 | } 66 | ); 67 | }); 68 | 69 | test('can see email', function () { 70 | $email = SentEmail::factory()->create(); 71 | 72 | $this->get(route('sentemails.email', $email))->assertOk(); 73 | }); 74 | 75 | test('can see email body', function () { 76 | $email = SentEmail::factory()->create(); 77 | 78 | $this->get(route('sentemails.body', $email))->assertOk(); 79 | }); 80 | 81 | test('can download attachment', function () { 82 | 83 | $filename = 'testfile.pdf'; 84 | $path = storage_path('app/public/testfile.pdf'); 85 | 86 | file_put_contents($filename, 'Test file content.'); 87 | 88 | $attachment = SentEmailAttachment::factory()->create([ 89 | 'filename' => $filename, 90 | 'path' => $path, 91 | ]); 92 | 93 | $this->get(route('sentemails.downloadAttachment', $attachment->id))->assertDownload($filename); 94 | 95 | unlink($filename); 96 | })->skip('fails on GH actions, need to investigate why'); 97 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | set('app.key', 'base64:'.base64_encode(Str::random(32))); 24 | 25 | // Setup default database to use sqlite :memory: 26 | $app['config']->set('database.default', 'mysql'); 27 | $app['config']->set('database.connections.mysql', [ 28 | 'driver' => 'sqlite', 29 | 'database' => ':memory:', 30 | 'prefix' => '', 31 | ]); 32 | $app['config']->set('sentemails.middleware', [ 33 | 'web', 34 | ]); 35 | } 36 | } 37 | --------------------------------------------------------------------------------