FriendsOfFlarum / pretty-mail

A Flarum extension that allows you to make custom html templates for emails!
MIT License
8 stars 1 forks source link

Beta 16 readiness - updater mailer to support laravel 8.x #13

Closed eddiewebb closed 3 years ago

eddiewebb commented 3 years ago

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

Screen Shot 2021-04-14 at 2 43 32 PM

Confirmed

hmm

 composer test

  [Symfony\Component\Console\Exception\CommandNotFoundException]  
  Command "test" is not defined. 
eddiewebb commented 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);
        });
    }
}