webCOMAND

Email Queue Content Type

The Email Queue content type is used to define an email queue used to store, send and retry sending email message, instead of just sending them immediately.

Settings

  • Title - Name of the queue.
  • Last Processed - Time the queue was last processed.
  • Send Immediately - Check to try to send emails immediately when queued, instead of next time the queue is processed.  If the email cannot be sent immediately, it will be queued for retry.
  • Max Attempt Count - The maximum number of times to try sending a given message
  • Max Batch Size - The maximum number of emails to process in one run. 0 will process all queued items.
  • Mail Sender - An optional sender object to configure how Emails are sent.
  • Mail Filters - JSON array of filter actions to be performed based on the email receipients. Recipients can be blocked, or emails can be redirected to alternative recipients based on full email addresses or domains.

Storage

  • Email Folder - Where to store the Email objects.
  • Queue Item Folder - The location to store Email Queue Item objects in.
  • Sent Items Keep (Days) - The number of days to keep successfully sent items before they should be automatically deleted. Duration is based on the queued item's last processed time. Both the queue items AND their associated emails will be deleted. Use 0 if they should never be deleted.
  • Failed Items Keep (Days) - The number of days to keep failed items before they should be automatically deleted. Duration is based on the queued item's last processed time. Both the queue items AND their associated emails will be deleted. Use 0 if they should never be deleted.

Items

  • Items - List of queued email items.

Example

The following example will send an HTML email using an email queue.

use \io_comand_script\ctemplate;

$repo = \comand::repo();
$log = new \io_comand_log\log();
$template = $repo->get_object_by_oid(123, 'EmailTemplate');
$queue = $repo->get_object_by_oid(456, 'EmailQueue');
$contacts = $repo->get('FROM Contact WHERE Subscribed');

// Send an HTML email to each contact through the queue.
for($contacts as $contact) {
    $opts = [ 'repo' => $repo, 'log' => $log, 'context' => $contact ];

    $mail = new \io_comand_email\mail();
    $mail->option('queue', $queue); 
    $mail->from = 'No Reply <no-reply@webcomand.com>';
    $mail->to = $contact->Name . ' <' . $contact->Email . '>';
    $mail->subject = ctemplate::run_ctemplate($template->Subject, $opts);
    $mail->message= ctemplate::run_ctemplate($template->Message, $opts);
    $mail->html(TRUE);
    $mail->header('X-Email-Client', 'webCOMAND');
    $mail->send();
}