Scripting to trigger "Welcome" email to new users


(Chris D) #1

I’ll be deploying Discourse across a fairly large user base across different departments soon. I will also set up groups in Discourse corresponding to the departments (i.e. IT, Business, etc.) What I’d like to be able to do is programmatically send out custom “welcome” emails based on the group and age of account (i.e. created in past 7 days), with some helpful links or information specific to the deparment… So example I want to send out something like:

"Hi IT User,

Welcome to Discourse!

Here are some helpful links to read…"

I see there’s an existing “Welcome User” email template under Admin\Customize\Email Templates. How do trigger it programmamtically just to the new accounts with a given age?

TIA,
Chris


(Gerhard Schlager) #2

That’s not possible. Discourse stores only a password hash. The real password (clear text) is unknown.


(Chris D) #3

Ok how about without password then ;)? I’ve updated my post.


(Gerhard Schlager) #4

What’s the use case for sending the username?
The user can use his email address to login if he doesn’t remember his username. :wink:


(Chris D) #5

let’s just say some of my user’s like to see things spelled out ;). the more pressing part is wanting to script this out so I can send the welcome emails to new users when I choose. If you have any input about that please share.


(Rafael dos Santos Silva) #6

If your company already have some authentication system in place, use the SSO feature, and they won’t even need to know username and password :thumbsup:.

Discourse SSO is very flexible, I got mine working in under a week, with full integration, including avatars.


(Chris D) #7

I am just going to remove the mention of the account info. I just want to script out to trigger the welcome email :)…


(Gerhard Schlager) #8

Log into your Docker container and start the Rails console:

cd /var/discourse
./launcher enter app
rails c

Then execute something like this (this is untested):

User.find_each {|user| user.enqueue_welcome_message('welcome_user')}

(Chris D) #9

Thanks @gerhard. What would I need to change to only send to users with accounts created past a certain date?


(Gerhard Schlager) #10

Something like this should work:

User.where('created_at >= ?', 7.days.ago).find_each {|user| user.enqueue_welcome_message('welcome_user')}

It sends the welcome message to all users that where created within the last 7 days.


(Chris D) #11

Awesome, thanks @gerhard! That worked!