Closed eddiewebb closed 3 years ago
I couldn't figure out how to get an instance of swiftmailer to instantiate our own mailer. laravel no longer exposes it in the container, but says you can get it via app('mailer')->getSwiftMailer()
but trying $swiftMailer = resolve('mailer')->getSwiftMailer();
throws a unhandled error I cant parse.
class MailerProvider extends AbstractServiceProvider
{
public function boot()
{
// Mostly copy-pasted from https://github.com/illuminate/mail/blob/v8.x/MailServiceProvider.php
$this->app->singleton('mailer', function (Container $container) {
$view = $container['view'];
$swiftMailer = resolve('mailer')->getSwiftMailer();
$mailer = new Mailer($view, $swiftMailer, $container['events']);
if ($container->bound('queue')) {
$mailer->setQueue($container['queue']);
}
$settings = app(SettingsRepositoryInterface::class);
$mailer->alwaysFrom($settings->get('mail_from'), $settings->get('forum_title'));
return $mailer;
});
$this->app->extend(NotificationMailer::class, function (NotificationMailer $mailer) {
return app(Overrides\NotificationMailer::class);
});
}
}
Fixes #12 for Beta 16
Changes proposed in this pull request: Instead of implementing mailer ourselves, this change updates to use Laravel 8.x mailmanager, and get a modified mailer instance from it.
Reviewers should focus on: THere was previously a custom fof
Mailer.php
that extended laravel's Mailer. Please confirm we're properly registering that instance in the manager to return later.Screenshot
Confirmed
composer test
).hmm