L
L
lexxvlad2020-12-25 21:30:51
Laravel
lexxvlad, 2020-12-25 21:30:51

Laravel 5.2 - how to send emails through a queue, through a separate connector?

I am not very strong in Laravel, I just understand it. I work with 5.2

There is a task - sending letters not directly during code execution, but postponed. Laravel has queues. They even have different drivers there, as it turned out
. In the project I'm working with, queues go through iron.io

But an external solution for sending emails with attachments is not an option, since these are again delays. It's better to do it locally. Especially since, in fact, the letters then leave the skull mailtrap.

In general, the sending code is now:

Mail::send($email_template, $view_vars, static function ($m) use ($customer, $company, $email_subject, $users, $invoice, $invoice_name) { $m->from($company->send_email, $company->name); $m->to($users, $customer->getFullName())->subject($email_subject); $m->attachData($invoice, $invoice_name); });

In order for letters to go to the local queue, is it possible to do this: ? And then the second question. If so, what additional code is needed for them to actually be sent or not? The Jobs table has already been created.

Mail::queue(.......)->onConnection('database');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Chubarov, 2020-12-26
@agoalofalife

It's still written in the documentation.

Можно через helper dispatch(new App\Jobs\SendEmail);
В контроллере
$job = (new SendEmail($user))->onQueue('emails');
$this->dispatch($job);

Specify connection if necessary.
If necessary, specify the onQueue queue, making it all into a chain.
well, then, for example, configure supervisor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question