@@ -26,7 +26,7 @@ public function boot()
26
26
Mail::swap ($ instance );
27
27
28
28
app ()->instance (MailerContract::class, $ instance );
29
-
29
+
30
30
if ($ this ->app ->runningInConsole ()) {
31
31
View::addNamespace ('helo ' , __DIR__ . '/../resources/views ' );
32
32
}
@@ -41,7 +41,7 @@ public function register()
41
41
$ this ->commands ([
42
42
TestMailCommand::class,
43
43
]);
44
-
44
+
45
45
$ this ->publishes ([
46
46
__DIR__ .'/../config/helo.php ' => base_path ('config/helo.php ' ),
47
47
], 'config ' );
@@ -50,11 +50,16 @@ public function register()
50
50
$ this ->mergeConfigFrom (__DIR__ .'/../config/helo.php ' , 'helo ' );
51
51
52
52
$ 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 ) {
54
56
return $ this ->createLaravel6Mailer ($ app );
55
57
}
58
+ if ($ version < 9 ) {
59
+ return $ this ->createLaravel7Mailer ($ app );
60
+ }
56
61
57
- return $ this ->createLaravel7Mailer ($ app );
62
+ return $ this ->createLaravel9Mailer ($ app );
58
63
});
59
64
}
60
65
@@ -112,6 +117,35 @@ protected function createLaravel7Mailer($app)
112
117
return $ mailer ;
113
118
}
114
119
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
+
115
149
protected function getConfig ($ name = 'smtp ' )
116
150
{
117
151
return $ this ->app ['config ' ]['mail.driver ' ]
0 commit comments