Scripting to trigger "Welcome" email to new users

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

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

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

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:

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.

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.

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

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')}
1 Like

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

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.

2 Likes

Awesome, thanks @gerhard! That worked!

1 Like

This topic was automatically closed after 3068 days. New replies are no longer allowed.