Approve a new user without sending a notice email

(liwei_swjtu) #1

Hi, I’m running my discourse under “require admin approval for new accounts” setting true.

When I sign up a new user, and successfully confirmed with told this:
“A moderator must manually approve your new account before you can access this forum. You’ll get an email when your account is approved!”

but I cant’s receive the notice email. I’ll been tried this three times and all failed, any helps?Thank you.

Confirm new users from Admin without using web link
(Jeff Atwood) #2

You can manually approve a user with no email needed, via the admin (wrench) button on the user’s page.

(liwei_swjtu) #3

sorry,but what I mean is the new user cann’t receive the notice email told the account has appoved.

(Chris Hunt) #4

Does any email get sent correctly from your server?

Do you have the setting send_welcome_message enabled in /admin/site_settings ?

(Jeff Atwood) #5

Correct, that is what I meant as well.

Even if the user’s email is totally broken, staff can manually approve their account via the admin (wrench) UI for the user. As pictured here, click the “Activate Account” button to do that.

(liwei_swjtu) #6

This isn’t what I’m talking about.

(liwei_swjtu) #7

I see this,but what I meant approved email is what discourse told when a new account is confirmed:
“A moderator must manually approve your new account before you can access this forum. You’ll get an email when your account is approved!”

(Chris Hunt) #8

I realize it’s confusing, but I think we are talking about the same thing. This is the code that gets called when you approve a user (app/models/user.rb):

def approve(approved_by)
  self.approved = true
  self.approved_by = approved_by
  self.approved_at =
  enqueue_welcome_message('welcome_approved') if save

At the bottom, you’ll see where the ‘welcome approved’ email is sent. If we look at the code for enqueue_welcome_message, notice that the email is only sent if the ‘send welcome message’ setting is enabled.

def enqueue_welcome_message(message_type)
  return unless SiteSetting.send_welcome_message?
  Jobs.enqueue(:send_system_message, user_id: id, message_type: message_type)

I was asking if you had this setting disabled because that would keep the message from sending :smiley:

This code was just updated yesterday, so if you update your Discourse installation, these “you’ve been approved” emails will go out no matter how you set the site setting. They’ll also be sent as an email, rather than site message. Give it a shot.

(liwei_swjtu) #9

Hi chrishunt, my site has enabled “enqueue_welcome_message”.as you said, the new version has the correct function, so after I pull up my site, it works what I want now.Thank you.
BTW:are you from china?I see the “zh_CN.yml” is updated by you.

(Chris Hunt) #10

No, I’m not from China. That probably has my name on it because I removed a translation that wasn’t being used.

(Joshua Frank) #11

The help text for send welcome message is:

Send all new users a welcome private message with a quick start guide

So, is that an email message or a PM when you join the site? I’d like the new user to get the PM, but not a welcome email.

(Joshua Frank) #12

Also, I disabled this and still got a message upon activation. Is there a way to create, approve, and activate a user without sending that user any emails.

(I want this because I want to control the messaging for my site by setting up and approving users with names according to a master database, and be able to send them an email of my own with a link to the site, where they can just click the link and be logged in.)

(Brad Marsh) #13

@joshfrank I accomplished this by using the PHP API developed by (thankyouverymuch) to send a user invite via my own site. They get the invite, and are logged in immediately when they follow the link.

(Unfortunately they subsequently need to go through the nonintuitive “reset my password” process to set a password with which they can re-login.)

The only itch I couldn’t scratch was that the discoursehosting API inviteUser() method assumed I wanted to invite someone to a particular topic, which I don’t. I finally settled on inviting new users to the “Welcome” topic (in my case, 36, found by trial and error). I couldn’t figure out how to just add them to a specific group without specifying a topic.

Here’s the URI for inviting someone to topic 1 and including him/her in groups 12 and 43 (43 is a custom one of mine).[your api key]&api_username=[your discourse username]&email=[]&topic_id=1&group_ids=12%2C43

If anybody can tell me how to structure a URI to add someone to a group via the REST API without specifying a topic, I’ll virtually buy you a virtual beer.

(Joshua Frank) #14

I’m not sure how to do exactly what you’re trying to do, but I solved a similar problem with a slightly different workflow:

create the user via /users

look up the user id of the user you just created via /admin/users/list/active.json?filter=your_user_email (no

add the user to the group via POST to /admin/users/{userId}/groups with Post Data group_id=your_group_id

Separating these stages has the risk that one call could fail, and leave the user in a corrupted state, but if that’s a worry, you could add a ton of error checking and try to roll previous stages back. I deal with it manually for now, because my scale isn’t that huge.

Hope this helps.

(Joshua Frank) #15

Is this still true? I’m creating users via the API (so I can control the format of the user names), and when I do this and then click Approve, the message is sent even though send_welcome_message is unchecked.