Download the PHP package taitava/silverstripe-emailqueue without Composer

On this page you can find all versions of the php package taitava/silverstripe-emailqueue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package silverstripe-emailqueue

silverstripe-emailqueue

This is a module that allows you to send emails in a background process, check previously sent emails, and monitor and cancel queued and scheduled emails. Also contains an an email templating structure that makes your email related code easier to manage via custom classes and .ss template files. Note that this module stores the email messages in a database.

Maintainer Contact

Jarkko Linnanvirta posti (at) taitavasti (dot) fi (in English or in Finnish) www.taitavasti.fi (only in Finnish)

Requirements

Installation

composer require taitava/silverstripe-emailqueue

Documentation

An important thing to notice is that this module does not change the way the default SilverStripe email messages are sent (for example the "forgot password" email message). Also email messages sent by the UserForms module is not affected by this module. Perhaps in the future, who knows. The idea is that you can use this module for your own, custom email messages.

So if you are sending email messages using this normal method:

Every time you use this method to send email messages, it will use the regular SilverStripe's process of sending emails. So nothing changes when you install this module.

When you want to send emails using this module and queueing, you will need to alter your code like this. Let's first define a new class for our email message:

And a template file MyEmailMessage.ss:

Then let's instantiate the message:

You can configure a default sender in YAML config:

And as you can see, we have passed a Member object to the setTo() method instead of a regular email address. With this module, you can always use whatever of the following as an email address:

As you may have already guessed, the EmailTemplate class extends the SilverStripe's Email class, so the same methods are available in EmailTemplate class too. When the queued messages are sent, the Email class is also used to handle the actual sending part, so we are not reinventing a wheel here.

Opt out from queueing?

Calling $email->send() will not actually send the message. It will queue it. If you wish to make an exception and send it immediately, you can call $email->send($message_id=null, $queue=false), and it will skip the queueing completely and send immediately. Note that in this case the email message is not even stored to the database at all, so you cannot monitor sent messages.

So when will my queued emails be sent?

Who knows if they will ever be sent.

Just joking. If you are already using the CronTask module, then there's actually nothing you need to do to send you messages. If not, it takes a little preparation. Install the module and then define a cron job in your server environment like so in the commandline:

hostname:~$ nano /etc/cron.d/silverstripe

* * * * * www-data php /var/www/my-silverstripe-project/framework/cli-script.php dev/cron

Then you are good to go. If you need more information about setting up cron tasks, please refer to the link above.

And to actually answer the question, you can configure the interval how often the queue is processed (= emails sent):

Where to see the queued and sent emails?

The only option for now is to use the Dashboard module. Just install it and then you can create a new dashboard panel of the class DashboardEmailQueue in your web browser. This is not the best solution but at least it provides quick glance on whether the email sendings are working correctly or if the queue is piling up. (If it's piling up, please, please don't try to create an automated email message that will alert you that sending email does not work! :D ).

Scheduling emails to be sent later (and cancelling the sending)

You can schedule particular email messages to be sent at a later time if you wish. Do this in your EmailTemplate subclass:

Note that the sending time is not minutely accurate. This is because the email queue is processed every ten minutes (by default) and there can be a lot of messages to process, so you can't know whether your message will be sent at 12:00, 12:01, or 12:02 etc... The time that you define declares an earliest time when the message can be sent. In theory, your message might get sent a year later than when the scheduled time was.

You are even able to cancel sending scheduled emails. If you are for example sending a notifying email message about a newly published blog post, but you end up to unpublish it for whatever reason, you can call EmailQueue::ScheduledEmails() in your code to get a DataList of emails waiting for their sending time to come, and then delete all those records so that they will never be sent.

Have I already sent a similar message?

When sending automated messages there can be cases where you might end up creating the same message to the same recipient over and over again. This is not an issue in simple cases such as "a user clicks on a button in a form -> send the form to an email address". But it might be an issue for example if email messages are created by a cron task that runs every day: "Get a list of members who haven't visited this application in 12 months and send them an email that we miss them."

If you just take a list of members whose last logged in date is a year ago (or longer), you will end up sending them a new message every day. One solution could be to only include members who have logged in exactly 365 days ago (within a 24h interval), but that can cause other problems if for example your server is down due to maintenance for one day and that cron task is not ran during that day. Or you are not sure whether you already ran it today and would like to rerun it just in case. This is when you would like to know if you have sent a similar message already or not.

And this is how you can do it very easily:

A note about development and testing environments

This module has a protection mechanism to not to send email messages accidentally to unintended addresses in development/testing phases (for example to client email addresses, which might be defined in your application's database).

You will need to visit your website's/application's SiteConfig section ("Settings" in the admin panel) and go to the "EmailQueue" tab. There you can see a field where you can define a list of allowed recipients. This list is only used in development/testing environments.

This is not the best possible solution because one might want to define this list in YAML config instead of in SiteConfig, but that's the way it is for now and this can be improved later.

TODO


All versions of silverstripe-emailqueue with dependencies

PHP Build Version
Package Version
Requires silverstripe/framework Version ~3.1
silverstripe/cms Version ~3.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package taitava/silverstripe-emailqueue contains the following files

Loading the files please wait ....