Support the ongoing development of Laravel.io →
Mail Queues Architecture

Hello.

In my app I have a form which allow the user to choose/insert: date/time, list of emails and text/subject of message. This is used to send emails.

The text/subject is inserted in the table CONVITE (cod_convite, subject, body).

The email and date/time are inserted in the table FILA (cod_fila, email, date, cod_convite).

Crons that run every minute are configured in the server.

I have this command to handle the table FILA. The emails are send using MANDRILL.

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class FilaCommand extends Command {

	protected $name = 'fila:disparar'; 
	protected $description = 'Something here.'; 

	public function fire() {

                // Looking for messages that should be send
		$agendados = Fila::where('date', '>=', 'CURDATE()')
					  ->orderBy('cod_fila', 'asc')
					  ->get();

		foreach ($agendados as $a) {

			$convite = Convite::where('cod_convite', '=', $a['cod_convite'])->first();

                        // Send
			Mail::send('emails.sample', array($convite['body']), function($message) {
	    	
		    	$message->from('sistema@teste.com', 'Test System');
		    	$message->to($a['email']);
		    	$message->subject($convite['subject']);

			});

			// Delete
			$fila_item = Fila::find($a['cod_fila']);
			$fila_item->delete();

		}

	}

}

About my code, I have the following questions:

Can this be done faster? Can my tables be improved?

Should I limit the emails sent for call, grouping them, or this is desnecessary?

Should I use mail:send or mail:queue?

How can I track the number of emails already sent to show in a page in the app?

How can I cancel a send?

Its possible to get and store in the database the result of 'mandrill send'?

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

destrutorx destrutorx Joined 13 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.