My web app is done with php on a Linux server, we use swift-mailer library to deliver emails from the web app to our own mail server.
The thing is that I need to keep track of every email (sent or not sent) the web server processes, so in case the mail server goes down we can re-send the emails that haven't been sent when the mail server is up again. Our business model relies on sending emails to customers.
In brief, we need to store every email that hasn't been sent for any reason (generally because mail server is down).
I guess this can is done checking $failures
parameter in SwiftMailer::send()
if an email hasn't been sent, and storing it in a database table (mail_failures) or in a file inside a directory (mail/failures/).
My proposal is:
- insert any mail in a send queue
- remove mail from the queue when sent, or change its status to failure if not sent
- use a cronjob to invoke a php script that handles mail sending from the queue
- report is there's any email with failure status in the queue*
I would use rather database tables than system files
Is this the correct way of doing it? Any ideas or ways to improve it? Any software that handles this automatically?
Could it be handled via ZeroMQ?