Jump to:

11004 Posts in 2735 Topics by 1824 members

All other Modules

SilverStripe Forums » All other Modules » Patched newsletter module (for 2.4.2)

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 2615 Views
  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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.

    Attached Files
  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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.

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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();
       $mailer->setMessageLimit(100);
       $mailer->flushQueue();
    }

    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.

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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 (www.critsend.com). Or does it also put a huge strain on the webserver?

  • Lukin
    Avatar
    Community Member
    42 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

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

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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 (http://dl.dropbox.com/u/1628064/newsletterDemo.zip) 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 www.critsend.com. Alternatives:

    http://sendgrid.com/
    http://postmarkapp.com/

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

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

  • dendeffe
    Avatar
    Community Member
    135 Posts

    Re: Patched newsletter module (for 2.4.2) Link to this post

    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 (info+1@testing.gmail.com, info+2@testing.gmail.com, etc…)

    2615 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.