-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1682 from bakaphp/hotfix-smtp-configuration
fix: smtp configuration per app
- Loading branch information
Showing
4 changed files
with
66 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kanvas\Notifications; | ||
|
||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
/** | ||
* we create a custom Mailable class to set the mailer configuration | ||
* at runtime, this is useful when we need to send emails using different | ||
* mailer configurations. | ||
*/ | ||
class KanvasMailable extends Mailable | ||
{ | ||
public function __construct( | ||
protected array $mailerConfig, | ||
protected string $emailContent | ||
) { | ||
} | ||
|
||
public function content(): Content | ||
{ | ||
return new Content( | ||
view: 'emails.layout', | ||
with: [ | ||
'html' => $this->emailContent, | ||
], | ||
); | ||
} | ||
|
||
public function build(): self | ||
{ | ||
if (app()->environment('testing')) { | ||
// Skip setting the custom mailer configuration in testing environment | ||
return $this; | ||
} | ||
|
||
//thanks to https://github.com/laravel/framework/issues/42602#issuecomment-1143637921 | ||
$customConfig = Mail::createSymfonyTransport($this->mailerConfig); | ||
Mail::setSymfonyTransport($customConfig); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters