#Queued Mailable

2 messages · Page 1 of 1 (latest)

barren wren
#

So I have a situtation where I want to queue a Mailable for 2hrs, but when I hit that 2hr mark I want to check a condition - if it's true, I want to cancel the queue job and not send the email. If it's false, I want to complete the queue job by sending the email. So I queue up the email like this:

Mail::to($request->user())->later(now()->addHours(2), new ApprovalEmail($data));

My Mailable class starts like so:

{
    use Queueable, SerializesModels;

Now, in a regular Job, I'd do the conditional check in a handle() function - but can I do that in a Mailable, or is queuing a Mailable somehow using it's own handler? Should I be using a regular Job instead to run the conditional check and then sending the Mailable from there (without queueing it?)

#

And if I can add a handle() function to the Mailable, how would I actually send the email from within that?