I'm doing some mass mailing tests but I'm finding the process being done with Laravel
slower. The reason I found the submission slow was that I worked in a company where on average 50 ~ 60 thousand emails were sent around 10 to 12 hours. To test the procedure I am using only 10 and in a first test it took 45 seconds to finish the process.
PROJECT STRUCTURE
Laravel 5.4. *
PostgreSQL database to store the names and emails of pseudo subscribers, basically I use only one table with 5 fields (ID, NAME, EMAIL, CREATED_AT, UPDATED_AT).
Sending emails are being done with the Laravel queue system using redis. I took the initiative to use the PHPREDIS extension contrary to the standard that already comes with Laravel which is the Predis, I did this because of the performance being superior.
FLOW
Link on the home page calling a route
<div class="links">
<a href="{{Route('enviarNews')}}">Enviar News</a>
</div>
The route calls this controller, which in turn calls a Job as you can see
<?php
namespace App\Http\Controllers;
use App\Jobs\MailJob;
class MailController extends Controller{
public function enviarNews(){
dispatch(new MailJob());
return 'Sua newsletter está em processo de preparo e sera enviada em breve.';
}
}
A Job, I'm calling the mail class.
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
use App\MailModel;
use App\Mail\MailSend;
class MailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
* @return void
*/
public function handle()
{
$mails = MailModel::all();
foreach ($mails as $mail){
Mail::to($mail->email)->send(new MailSend($mail));
}
}
}
MailSend and View class
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\MailModel;
class MailSend extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
* @return void
*/
public $mail;
public function __construct(MailModel $mail)
{
$this->mail = $mail;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from("[email protected]", "Firemail Testes")
->subject("Testes de Envio em Massa")
->view('mail.news1');
}
}
View
<p>Ola {{$mail->name}}, estamos testando o envio de emails em massa!</p>
That's what's being done, anything in my code may be slow shipping? For the accounts I made, with this current metric could only be sending about 19200 emails per day, well below the one I mentioned above and taking advantage, can this slowdown be caused by my SMTP server? for these tests am I using SMTP2GO ?
-
Can it also be on my internet account? (But on average it runs at 30mb.)
-
What can I do to improve this process and leave as soon as possible?