File tree 5 files changed +62
-1
lines changed
5 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 58
58
*/
59
59
60
60
'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 ),
61
74
];
Original file line number Diff line number Diff line change @@ -53,4 +53,14 @@ public static function cronjobEmailLimit()
53
53
{
54
54
return config ('laravel-database-emails.limit ' , 20 );
55
55
}
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
+ }
56
66
}
Original file line number Diff line number Diff line change @@ -271,6 +271,12 @@ public function send()
271
271
272
272
$ this ->email ->save ();
273
273
274
- return $ this ->email ->fresh ();
274
+ $ this ->email ->refresh ();
275
+
276
+ if (Config::sendImmediately ()) {
277
+ $ this ->email ->send ();
278
+ }
279
+
280
+ return $ this ->email ;
275
281
}
276
282
}
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ public function prepare(EmailComposer $composer)
34
34
$ this ->prepareAttachments ($ composer );
35
35
36
36
$ this ->prepareScheduled ($ composer );
37
+
38
+ $ this ->prepareImmediately ($ composer );
37
39
}
38
40
39
41
/**
@@ -221,4 +223,16 @@ private function prepareScheduled(EmailComposer $composer)
221
223
'scheduled_at ' => $ scheduled ->toDateTimeString (),
222
224
]);
223
225
}
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
+ }
224
238
}
Original file line number Diff line number Diff line change 5
5
use Dompdf \Dompdf ;
6
6
use Swift_Events_SendEvent ;
7
7
use Illuminate \Support \Facades \Mail ;
8
+ use Stackkit \LaravelDatabaseEmails \Email ;
9
+ use Stackkit \LaravelDatabaseEmails \Config ;
8
10
9
11
class SenderTest extends TestCase
10
12
{
@@ -212,6 +214,22 @@ public function raw_attachments_are_added_to_the_email()
212
214
$ this ->assertContains ('Hello CI! ' , $ attachment ->getBody ());
213
215
}
214
216
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
+
215
233
/** @test */
216
234
public function raw_attachments_are_not_added_if_the_data_is_not_valid ()
217
235
{
You can’t perform that action at this time.
0 commit comments