@@ -26,7 +26,7 @@ public function boot()
2626 Mail::swap ($ instance );
2727
2828 app ()->instance (MailerContract::class, $ instance );
29-
29+
3030 if ($ this ->app ->runningInConsole ()) {
3131 View::addNamespace ('helo ' , __DIR__ . '/../resources/views ' );
3232 }
@@ -41,7 +41,7 @@ public function register()
4141 $ this ->commands ([
4242 TestMailCommand::class,
4343 ]);
44-
44+
4545 $ this ->publishes ([
4646 __DIR__ .'/../config/helo.php ' => base_path ('config/helo.php ' ),
4747 ], 'config ' );
@@ -50,11 +50,16 @@ public function register()
5050 $ this ->mergeConfigFrom (__DIR__ .'/../config/helo.php ' , 'helo ' );
5151
5252 $ this ->app ->singleton (Mailer::class, function ($ app ) {
53- if (version_compare ($ app ->version (), '7.0.0 ' , '< ' )) {
53+ $ version = (int ) Str::of ($ app ->version ())->explode ('. ' )->first ();
54+
55+ if ($ version < 7 ) {
5456 return $ this ->createLaravel6Mailer ($ app );
5557 }
58+ if ($ version < 9 ) {
59+ return $ this ->createLaravel7Mailer ($ app );
60+ }
5661
57- return $ this ->createLaravel7Mailer ($ app );
62+ return $ this ->createLaravel9Mailer ($ app );
5863 });
5964 }
6065
@@ -112,6 +117,35 @@ protected function createLaravel7Mailer($app)
112117 return $ mailer ;
113118 }
114119
120+ protected function createLaravel9Mailer ($ app )
121+ {
122+ $ defaultDriver = $ app ['mail.manager ' ]->getDefaultDriver ();
123+ $ config = $ this ->getConfig ($ defaultDriver );
124+
125+ // We get Symfony Transport from Laravel 9 mailer
126+ $ symfonyTransport = $ app ['mail.manager ' ]->getSymfonyTransport ();
127+
128+ // Once we have create the mailer instance, we will set a container instance
129+ // on the mailer. This allows us to resolve mailer classes via containers
130+ // for maximum testability on said classes instead of passing Closures.
131+ $ mailer = new Laravel7Mailer (
132+ 'smtp ' , $ app ['view ' ], $ symfonyTransport , $ app ['events ' ]
133+ );
134+
135+ if ($ app ->bound ('queue ' )) {
136+ $ mailer ->setQueue ($ app ['queue ' ]);
137+ }
138+
139+ // Next we will set all of the global addresses on this mailer, which allows
140+ // for easy unification of all "from" addresses as well as easy debugging
141+ // of sent messages since they get be sent into a single email address.
142+ foreach (['from ' , 'reply_to ' , 'to ' , 'return_path ' ] as $ type ) {
143+ $ this ->setGlobalAddress ($ mailer , $ config , $ type );
144+ }
145+
146+ return $ mailer ;
147+ }
148+
115149 protected function getConfig ($ name = 'smtp ' )
116150 {
117151 return $ this ->app ['config ' ]['mail.driver ' ]
0 commit comments