File tree Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 5858 */
5959
6060 'limit ' => 20 ,
61+
62+ /*
63+ |--------------------------------------------------------------------------
64+ | Send E-mails Immediately
65+ |--------------------------------------------------------------------------
66+ |
67+ | Sends e-mails immediately after calling send() or schedule(). Useful for development
68+ | when you don't have Laravel Scheduler running or don't want to wait up to
69+ | 60 seconds for each e-mail to be sent.
70+ |
71+ */
72+
73+ 'immediately ' => env ('LARAVEL_DATABASE_EMAILS_SEND_IMMEDIATELY ' , false ),
6174];
Original file line number Diff line number Diff line change @@ -53,4 +53,14 @@ public static function cronjobEmailLimit()
5353 {
5454 return config ('laravel-database-emails.limit ' , 20 );
5555 }
56+
57+ /**
58+ * Determine if e-mails should be sent immediately.
59+ *
60+ * @return bool
61+ */
62+ public static function sendImmediately ()
63+ {
64+ return (bool ) config ('laravel-database-emails.immediately ' , false );
65+ }
5666}
Original file line number Diff line number Diff line change @@ -271,6 +271,12 @@ public function send()
271271
272272 $ this ->email ->save ();
273273
274- return $ this ->email ->fresh ();
274+ $ this ->email ->refresh ();
275+
276+ if (Config::sendImmediately ()) {
277+ $ this ->email ->send ();
278+ }
279+
280+ return $ this ->email ;
275281 }
276282}
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ public function prepare(EmailComposer $composer)
3434 $ this ->prepareAttachments ($ composer );
3535
3636 $ this ->prepareScheduled ($ composer );
37+
38+ $ this ->prepareImmediately ($ composer );
3739 }
3840
3941 /**
@@ -221,4 +223,16 @@ private function prepareScheduled(EmailComposer $composer)
221223 'scheduled_at ' => $ scheduled ->toDateTimeString (),
222224 ]);
223225 }
226+
227+ /**
228+ * Prepare the e-mail so it can be sent immediately.
229+ *
230+ * @param EmailComposer $composer
231+ */
232+ private function prepareImmediately (EmailComposer $ composer )
233+ {
234+ if (Config::sendImmediately ()) {
235+ $ composer ->getEmail ()->fill (['sending ' => 1 ]);
236+ }
237+ }
224238}
Original file line number Diff line number Diff line change 55use Dompdf \Dompdf ;
66use Swift_Events_SendEvent ;
77use Illuminate \Support \Facades \Mail ;
8+ use Stackkit \LaravelDatabaseEmails \Email ;
9+ use Stackkit \LaravelDatabaseEmails \Config ;
810
911class SenderTest extends TestCase
1012{
@@ -212,6 +214,22 @@ public function raw_attachments_are_added_to_the_email()
212214 $ this ->assertContains ('Hello CI! ' , $ attachment ->getBody ());
213215 }
214216
217+ /** @test */
218+ public function emails_can_be_sent_immediately ()
219+ {
220+ $ this ->app ['config ' ]->set ('laravel-database-emails.immediately ' , false );
221+ $ this ->sendEmail ();
222+ $ this ->assertCount (0 , $ this ->sent );
223+ Email::truncate ();
224+
225+ $ this ->app ['config ' ]->set ('laravel-database-emails.immediately ' , true );
226+ $ this ->sendEmail ();
227+ $ this ->assertCount (1 , $ this ->sent );
228+
229+ $ this ->artisan ('email:send ' );
230+ $ this ->assertCount (1 , $ this ->sent );
231+ }
232+
215233 /** @test */
216234 public function raw_attachments_are_not_added_if_the_data_is_not_valid ()
217235 {
You can’t perform that action at this time.
0 commit comments