Plugin to store mail in a queue for later sendout.
When working with emails on a webservice sending email blocks the http request until the email is actually sent out. This can be frustrating for a user especially if the smtp server does not respond promptly.
With this plugin you can save the mail to a local queue file and invoke the actual transport for example with a cron fired cake shell command.
If you are using composer simply add the following requirement to your composer file:
"hakito/cakephp-mailqueue-plugin": ">=1.2"
Otherwise download the plugin to app/Plugin/Mailqueue.
Simply load the plugin in your bootstrap:
CakePlugin::load('Mailqueue');
Add a new entry to the app/Config/email.php or replace it with an existing one.
class EmailConfig
{
public $queue = array(
// required:
'transport' => 'Mailqueue.Queue',
'from' => '[email protected]',
// optional:
'queueFolder' => '/tmp/mailqueue', // storage location for mailqueue
'requeue' => array(300, 500, 1000) // requeue after x seconds in case of an error
);
// Your existing config
public $smtp = array(...)
}
Send mail to the queue as usually in cake
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('queue');
// place your content in $email
$email->send();
Use cake shell to do the real sendout. The shell script requires 2 arguments. The first is the name of your queue configuration and the second the name of the config to use for the real sendout.
In your app directory execute:
Console/cake Mailqueue.SendMail queue smtp
Every donation is welcome
- PayPal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7L95X7SB9B42N
- Bitcoin: 1NUrWv9zkYaKjLf8zGwk1R6WtgxFPnEBcP