在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spatie/laravel-mail-preview开源软件地址(OpenSource Url):https://github.com/spatie/laravel-mail-preview开源编程语言(OpenSource Language):PHP 97.1%开源软件介绍(OpenSource Introduction):A mail driver to quickly preview mailThis package can display a small overlay whenever a mail is sent. The overlay contains a link to the mail that was just sent. This can be handy when testing out emails in a local environment. Support usWe invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall. InstallationYou can install the package via composer: composer require spatie/laravel-mail-preview Configuring the mail transportThis package contains a mail transport called // in config/mail.php
'mailers' => [
'smtp' => [
'transport' => 'preview',
// ...
],
// ...
], Registering the preview middleware routeThe package can display a link to sent mails whenever they are sent. To use this feature, you must add the // in app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
// other middleware
\Spatie\MailPreview\Http\Middleware\AddMailPreviewOverlayToResponse::class,
],
// ...
]; You must also add the // in routes/web.php
Route::mailPreview(); This will register a route to display sent mails at Route::mailPreview('custom-url-where-sent-mails-will-be-shown'); Publishing the config fileOptionally, you can publish the config file with: php artisan vendor:publish --provider="Spatie\MailPreview\MailPreviewServiceProvider" --tag="mail-preview-config" This is the content of the config file that will be published at return [
/*
* By default, the overlay will only be shown and mail will only be stored
* when the application is in debug mode.
*/
'enabled' => env('APP_DEBUG', false),
/*
* All mails will be stored in the given directory.
*/
'storage_path' => storage_path('email-previews'),
/*
* This option determines how long generated preview files will be kept.
*/
'maximum_lifetime_in_seconds' => 60,
/*
* When enabled, a link to mail will be added to the response
* every time a mail is sent.
*/
'show_link_to_preview' => true,
/*
* Determines how long the preview pop up should remain visible.
*
* Set this to `false` if the popup should stay visible.
*/
'popup_timeout_in_seconds' => 8,
]; Publishing the viewsOptionally, you can publish the views that render the preview overlay and the mail itself. php artisan vendor:publish --provider="Spatie\MailPreview\MailPreviewServiceProvider" --tag="mail-preview-views" You can modify the views that will be published at UsageEverytime an email is sent, an
You can open the Preview in a web browserWhen you open the At the beginning of the generated file you'll find an HTML comment with all the message info: <!--
From:{"[email protected]":"Acme HQ"},
to:{"[email protected]":"Jack Black"},
reply-to:{"[email protected]"},
cc:[{"[email protected]":"Acme Finance"}, {"[email protected]":"Acme Management"}],
bcc:null,
subject:Invoice #000234
--> EventsWhenever a mail is stored on disk, the
Making assertions against sent mailsCurrently, using Laravel's The This allows you to make assertions on the content of a mail, without having the mailable in scope. // in a test
Artisan::call(CommandThatSendsMail::class);
Spatie\MailPreview\Facades\SentMails::assertLastContains('something in your mail'); Let's explain other available assertions method using this mailable as example. namespace App\Mail;
use Illuminate\Mail\Mailable;
class MyNewSongMailable extends Mailable
{
public function build()
{
$this
->to('[email protected]')
->cc('[email protected]')
->bcc('[email protected]')
->subject('Here comes the sun')
->html("It's been a long cold lonely winter");
}
} In your code you can send that mailable with: Mail::send(new MyNewSongMailable()); In your tests you can assert that the mail was sent using the use Spatie\MailPreview\Facades\SentMails;
use \Spatie\MailPreview\SentMails\SentMail;
SentMails::assertSent(fn (SentMail $mail) => $mail->bodyContains('winter')); // will pass
SentMails::assertSent(fn (SentMail $mail) => $mail->bodyContains('spring')); // will not pass You can use as many assertion methods on the SentMails::assertSent(function (SentMail $mail) {
return
$mail->subjectContains('sun') &&
$mail->hasTo('[email protected]')
$mail->bodyContains('winter'); The
Additionally, the
The
Additionally,
ChangelogPlease see CHANGELOG for more information on what has changed recently. UPGRADINGPlease see UPGRADING for what to do to switch over from ContributingPlease see CONTRIBUTING for details. Security VulnerabilitiesPlease review our security policy on how to report security vulnerabilities. CreditsThe initial version of this package was created by Mohamed Said, who graciously entrusted this package to us at Spatie. LicenseThe MIT License (MIT). Please see License File for more information. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论