• Community Rep

    Huh, that's strange one doesn't exist yet, I looked around for a bit and couldn't find one.

    Anyway, the methods were pretty easy to figure out, I can fancy this up and package it later today.

    	var sender_uid = 0, start = 0, limit = 100;
    	async.waterfall([
    		function (next) {
    			db.getObjectField('global', 'userCount', next);
    		},
    		function (count, next) {
    			User.getUsersFromSet('users:joindate', sender_uid, start, count, next);
    		},
    		function (users, next) {
    			console.log('Sending emails to users ('+users.length+'): ');
    			async.eachLimit(users, limit, function(userObj, next) {
    				console.log('sending to uid ' + userObj.uid);
    				emailer.send('test', userObj.uid, {  // templates/emails/test.tpl
    					subject: 'Test Email',
    					username: userObj.username
    				});
    				return next();
    			}, next);
    		}
    	], function (err, results) {
    		console.log('Done sending emails.');
    	});
    

  • If you use mandrill as an emailer. You can export your users as a csv file and load them into mandrill and email from there.

  • NodeBB

    @yariplus You don't have to get the userCount you can use -1 for the getUsersFromSet method and it will grab all the uids.

    Ideally though since you only need username/uid you can grab that directly instead of calling getUsersFromSet which does a bunch of other stuff.

        var sender_uid = 0, limit = 100;
        async.waterfall([
            function(next) {
                  db.getSortedSetRange('users:joindate', 0, -1, next);
            },
            function (next) {
                User.getMultipleUserFields(uids, ['uid', 'username'], next);
            },
            function (users, next) {
                console.log('Sending emails to users ('+users.length+'): ');
                async.eachLimit(users, limit, function(userObj, next) {
                    console.log('sending to uid ' + userObj.uid);
                    emailer.send('test', userObj.uid, {  // templates/emails/test.tpl
                        subject: 'Test Email',
                        username: userObj.username
                    });
                    return next();
                }, next);
            }
        ], function (err, results) {
            console.log('Done sending emails.');
        });
    
  • Community Rep

    @a_5mith That's sounds like a good/better way to do it.

    Do you think there would be any problems with the way I send them above?

  • Community Rep

    @baris Ah! Wonderful. Thank you.

  • Community Rep

    Here you go

    I added a drop-down with all the groups instead of always sending to everyone.

    I also remove any user who is banned.

    ss+(2015-05-13+at+09.54.02).png

    Issues/Todos:

    • It squashes everything in the body into one line, there's probably a quick fix for that, but what I really want to have is a composer-like area.
    • It seems to always send the email as plain text.
    • Would be nice to have a checkbox that also creates a new topic for the newsletter.
    • Needs to have an unsubscribe functionality.

  • Depending on the email plugin you use this can be made pretty simple. Although @yariplus has basically solved your problem, if you are using mailgun you can send out a mass emial via the csv download from the ACP.

    I wrote a little blog post about this a while back - http://blog.bitbangers.co.uk/sending-emails-with-python-and-mailgun/

  • Plugin & Theme Dev

    @yariplus testing it, thanks for the effort

  • Plugin & Theme Dev

    teste it and works perfect , email received only the groups selected
    only problem is the plan text, it doesn't let you line breaks etc
    thanks for the good job


  • Pretty sure you'd need to set the content type.

    Content-Type": "text/html" Or something like that.

Suggested Topics

| |