8

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?

miho
  • 10,856
  • 6
  • 37
  • 78
  • For these type of jobs I use nodejs API solution – iam batman May 16 '17 at 15:39
  • Please refer this document too along with the answer by Sandeesh, https://laravel.com/docs/5.4/scheduling – manian May 16 '17 at 15:42
  • 1
    @manian 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. – Sandeesh May 16 '17 at 15:49
  • 2
    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? – jeff-h Jul 28 '17 at 04:02

1 Answers1

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

Sandeesh
  • 9,590
  • 2
  • 24
  • 37
  • 1
    Ok, I see it uses the queue system. Sadly Amazons SQS doesn't support delays longer then 15 minutes. :( – miho May 16 '17 at 15:57
  • 1
    @miho 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.` – Sandeesh May 16 '17 at 15:59
  • Yes, I read that. And I also cross checked with Amazons own documentation, but that's still the case (http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-timers.html). – miho May 16 '17 at 16:02
  • Thanks. I was lost at the same problem. I was fixed but your answer is well. – vanloc Jun 05 '17 at 16:35