Skip to content

Commit d27c130

Browse files
committed
fix: Optimized the email sending logic and added pipeline handling in the exception notification feature
1 parent e0c9238 commit d27c130

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

config/exception-notify.php

+4-23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Guanguans\LaravelExceptionNotify\Pipes\AddKeywordPipe;
1515
use Guanguans\LaravelExceptionNotify\Pipes\FixPrettyJsonPipe;
1616
use Guanguans\LaravelExceptionNotify\Pipes\LimitLengthPipe;
17+
use Guanguans\LaravelExceptionNotify\Pipes\SprintfHtmlPipe;
1718
use Guanguans\LaravelExceptionNotify\ReportUsingCreator;
1819

1920
return [
@@ -93,36 +94,13 @@
9394
* The default reported channels.
9495
*/
9596
'defaults' => env_explode('EXCEPTION_NOTIFY_DEFAULTS', [
96-
// 'bark',
97-
// 'chanify',
98-
// 'dingTalk',
99-
// 'discord',
100-
// 'dump',
101-
// 'feiShu',
10297
'log',
103-
// 'mail',
104-
// 'null',
105-
// 'pushDeer',
106-
// 'qqChannelBot',
107-
// 'serverChan',
108-
// 'slack',
109-
// 'telegram',
110-
// 'weWork',
111-
// 'xiZhi',
11298
]),
11399

114100
/**
115101
* The list of channels.
116102
*/
117103
'channels' => [
118-
'aggregate' => [
119-
'channels' => [
120-
'log',
121-
'lark',
122-
'weWork',
123-
],
124-
],
125-
126104
/**
127105
* 飞书群机器人.
128106
*/
@@ -157,6 +135,9 @@
157135
'mail' => [
158136
'mailer' => null,
159137
'to' => '[email protected]',
138+
'pipes' => [
139+
SprintfHtmlPipe::class,
140+
],
160141
],
161142

162143
/**

src/Channels/MailChannel.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515

1616
use Guanguans\LaravelExceptionNotify\Mail\ExceptionReportMail;
1717
use Illuminate\Mail\Mailable;
18-
use Illuminate\Mail\Mailer;
1918
use Illuminate\Support\Facades\Mail;
2019
use Illuminate\Support\Str;
2120

2221
class MailChannel extends Channel
2322
{
2423
public function report(string $report): void
2524
{
26-
tap(Mail::driver($this->config->get('mailer')), function (Mailer $mailer): void {
27-
collect($this->config->all())
28-
->except(['mailer'])
29-
->each(static function ($value, string $key) use ($mailer): void {
30-
$mailer->{Str::camel($key)}($value);
31-
});
32-
})->send($this->createMail($report));
25+
collect($this->config->all())
26+
->except(['mailer', 'pipes'])
27+
->reduce(
28+
static fn ($carry, $value, string $key) => $carry->{Str::camel($key)}($value),
29+
Mail::driver($this->config->get('mailer'))
30+
)
31+
->send($this->createMail($report));
3332
}
3433

3534
private function createMail(string $report): Mailable

src/Mail/ExceptionReportMail.php

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(string $report)
2727
public function build(): self
2828
{
2929
return $this
30+
->subject(config('exception-notify.title'))
3031
->html($this->report);
3132
}
3233
}

0 commit comments

Comments
 (0)