Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Laravel schedule mails for later sending?

The Laravel Documentation describes the ability to schedule a mail for later delivery, with the following example:

$when = Carbon::now()->addMinutes(10);

Mail::to($request->user())
    ->cc($moreUsers)
    ->bcc($evenMoreUsers)
    ->later($when, new OrderShipped($order));

No further configuration is mentioned in the documentation (no database tables or whatever seem to be required by that feature). But I'm wondering, how does that work? Where does Laravel stores the information for later retrieval.

Is this feature reliable for longer durations? I want to send a mail to the user 3 days after sign up. May there be the possibility that the mail gets lost? For example when restarting the server?

like image 321
miho Avatar asked May 16 '17 15:05

miho


1 Answers

From the same doc you linked

This method will automatically take care of pushing a job onto the queue so the message is sent in the background. Of course, you will need to configure your queues before using this feature.

Laravel uses queues to take care of this. You need to enable queuing in the mailable that you're sending. The mail delayed sending also uses the same queues. To make use of this feature you need to have a queue setup and a queue listener or worker running to process the queues. Check the queues doc for more information on this.

https://laravel.com/docs/5.4/queues

like image 78
Sandeesh Avatar answered Oct 18 '22 00:10

Sandeesh