Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

netdjw's avatar
Level 15

Laravel queue mail sending

Is there anybody who can help me understand the working logic of queued e-mail sending?

I need to extend e-mail sending options and I need to understand how it's happening, how it's working when a Mailable, ShouldQueue class is queued.

Thanks!

0 likes
6 replies
kevinbui's avatar

I have just read the source code. When you queue a mailable, The following methods will be called in this order:

1. Illuminate\Mail\MailManager::queue();
2. Illuminate\Mail\Mailable::queue();

In the second step, a job instance of type Illuminate\Mail\SendQueuedMailable will wrap your mailable before being dispatched to a queue.

netdjw's avatar
Level 15

@kevinbui thanks. And how can I use my custom logic when mail actually sending? I want to change the SMTP settings in every case depends on the Job's tenant property.

krisi_gjika's avatar

@netdjw what settings do you want to change exactly? Do you want to build your own driver on the fly?

netdjw's avatar
Level 15

@krisi_gjika This is the situation:

I have multiple tenants in the app. Each tenant has it's own SMTP user, password, host, etc. And each tenant expect to send their e-mails with their SMTP account and server.

The app handles e-mails via notification and queue.

I pass the tenant's information into the mail jobs, but not the exact SMTP infos, because of security reasons.

So the problem is when the mail job is placed into the queue it contains only the tenant's data, for example name, id. And I need to parse the job to find out SMTP datas when the queue worker pick up the job from the queue.

And this last step is a mistery to me.

krisi_gjika's avatar

@netdjw do these setting changes often or are they mostly constant once they have been set up? If they are constant you can just add them into mail.php and update the mailer to what you need inside the notification class:

public function toMail($notifiable)
{
  return (new MailMessage)
    ->mailer($this->tenant->mailer) // "tenants_smtp"
    ->line('...');
}

Please or to participate in this conversation.