Send email to users?
-
Any plugin to send email to all users around there? useful to newsletter or urgent notification to the community.
-
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.'); });
-
@yariplus You don't have to get the
userCount
you can use-1
for thegetUsersFromSet
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.'); });
-
Here you go
https://www.npmjs.com/package/nodebb-plugin-newsletterI added a drop-down with all the groups instead of always sending to everyone.
I also remove any user who is banned.
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/
-
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