Skip to content

Commit

Permalink
Restart swiftmailer after each email sent to remove temp files - closes
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed May 2, 2023
1 parent 3c3f25a commit 1398f02
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/Listeners/RestartSwiftMailer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Listeners;

class RestartSwiftMailer
{

/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handle($event)
{
// Destroy Swift mailer to make it clean temp files.
// https://github.com/freescout-helpdesk/freescout/issues/2949
// https://github.com/swiftmailer/swiftmailer/issues/1287#issuecomment-833505298
\App::forgetInstance('mailer');
\App::forgetInstance('swift.mailer');
\App::forgetInstance('swift.transport');
}
}
4 changes: 4 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class EventServiceProvider extends ServiceProvider
'App\Listeners\ProcessSwiftMessage',
],

'Illuminate\Mail\Events\MessageSent' => [
'App\Listeners\RestartSwiftMailer',
],

'Illuminate\Auth\Events\Registered' => [
'App\Listeners\LogRegisteredUser',
],
Expand Down

0 comments on commit 1398f02

Please sign in to comment.