Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Patched newsletter module (for 2.4.2)

Go to End

21 Posts   3583 Views


Community Member, 288 Posts

15 October 2010 at 12:05am

I implemented the trunk version of SwiftMailer (the one used in Symfony) as a mailer for SilverStripe. It contains the spools so you can easily spool messages and send them out later if you want. The way I've made it work is that when spooling is on then Email->send() will just spool the message.

Then you can setup a cron job or whatever to just work its way through the queue. I've attached the code for it so you can try it out if you like. It's still pretty early code so it's mostly with my needs in mind. Let me know if it gives you any trouble or if you have any good ideas about how to develop it further.

I've made it as a module so just place the swiftmailer folder in the root of your project.


Community Member, 135 Posts

15 October 2010 at 1:12am

Great, I had SwiftMailer included in SilverStripe, but this is already a lot cleaner. Thanks.

Still have to find out more about sending it 'in the background'. Don't have to much knowledge of spooling. And part seems to be a bit underdocumented in the, otherwise really great, SwiftMailer documentation.


Community Member, 288 Posts

15 October 2010 at 1:42am

Edited: 15/10/2010 1:43am

Yeah I far as I understand it the spooling functionality isn't included yet in the stable release but since Symfony uses the version with spooling I felt pretty secure with using that vesion as well.

It works like this:

First turn on spooling when activating the mailer in the _config.php

$mailer = new SwiftMailer($host, $port, $userName, $password, true);

If you want to set some limits on the spooling you can do so either in the config or when flushing the queue. The limits available on the spool is setMessageLimit() and setTimeLimit().
What happens when the spooling is on is that $email->send() will only save the file to disk, it won't actually send the email. Make sure that the messages folder in swiftmailer is writable for this functionality.

What I do then is setup a separate function for actually sending the messages. It can look something like this:

public function flush_queue() {
	$email = new Email();
	$mailer = $email->mailer();

The queue is global and all the info is stored in the messages so that's all you have to do. Now you can for example setup a cron job that contacts a certain URL regularly and the queue will processed 100 messages at a time in this instance. If you want some other message limit or perhaps a time limit then you can set that instead.

Let me know if you need any help.


Community Member, 135 Posts

15 October 2010 at 4:56am

Smurfkas, you mean setting up the cron job in, for instance cPanel, right?

Would this be using the newsletter Module?
Have you tested it with for instance a cron job that runs hourly and sends, say, 500 mails? I’m going to use a dedicated SMTP server ( Or does it also put a huge strain on the webserver?


Community Member, 56 Posts

29 October 2010 at 8:56pm

Edited: 29/10/2010 8:57pm

Could you please post a download-link to the newslette-mod.
Can't find it...


Community Member, 135 Posts

30 October 2010 at 2:32am

I've got it working pretty well now.

I'm using the swift mailer class and a class to put styles inline. Here's a link ( to a stripped down version (I removed my theme, other classes that have nothing to do with the newsletter) of my SilverStripe install.

It's loading messages as files to my server. Then I use a CRON JOB that contacts MailCronSender (which has an extra Director::addRules) every 30 minutes. It then sends out the ammount of messages you specify in $mailer->spool->setMessageLimit(4); in swiftmailer > _config.php.

For the SMTP server, I'm using Alternatives:


Forum Moderator, 1899 Posts

30 October 2010 at 2:35am

Much appreciated contribution :)
I'll be using this very soon!


Community Member, 135 Posts

30 October 2010 at 3:03am

Right, there's also a quick and dirty function (build_testlist) on MailCronSender.php you can use to build a list of test addresses you can put the result in a CSV file and import that in SS.

I tested by sending to a dummy gmail account. You can add extra paramaters to your adress (,, etc…)