Laravel Mailer Callback when using Queue

Viewed 1384

Is there a way to pass a callback function to Laravel's mailer?

I'm using the Mail facade with a mailable class, which is sending out an attachment. I would like to delete the attached file form storage once the email is sent.

The email job is being queue

Mail::to($user)->send(new MyMailable($file));

I wasn't able to use the Mailer fired event (https://laravel.com/docs/5.4/mail#events). One reason, because the event happens before the email is sent, meaning I wouldn't be able to delete the file at that moment, or the message won't have the attachment. Second, the application has multiple email jobs, some where the attachment must be deleted, and others where it won't be. The event data has the swiftmailer instance only, with no extra information about the job itself (data in mailable for ex.).

1 Answers
Related