How does Laravel schedule mails for later sending?
Asked Answered
L

1

10

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?

Leverage answered 16/5, 2017 at 15:35 Comment(4)
For these type of jobs I use nodejs API solutionGannes
Please refer this document too along with the answer by Sandeesh, laravel.com/docs/5.4/schedulingNinon
@Ninon mail delayed delivery doesn't use scheduling and you don't need to set up a scheduler for this. It works by setting the delay in the queue channel.Arabeila
Nobody has really addressed the last question: "Is this feature reliable for longer durations?" I know Amazon SQS only allows 15 mins but I am running my own beanstalk. Can I schedule a specific email to send in three days from now?Lamas
A
11

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

Arabeila answered 16/5, 2017 at 15:41 Comment(4)
Ok, I see it uses the queue system. Sadly Amazons SQS doesn't support delays longer then 15 minutes. :(Leverage
@Leverage Ye that's a real let down. The folks clearly warn about that in the doc too. The Amazon SQS queue service has a maximum delay time of 15 minutes.Arabeila
Yes, I read that. And I also cross checked with Amazons own documentation, but that's still the case (docs.aws.amazon.com/AWSSimpleQueueService/latest/…).Leverage
Thanks. I was lost at the same problem. I was fixed but your answer is well.Jeremy

© 2022 - 2024 — McMap. All rights reserved.