# Welcome email not sent when adding user from console

**URL:** https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765
**Category:** Support
**Created:** [March 23, 2017, 1:36pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765 "2017-03-23T13:36:02Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![nordize](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@nordize](https://meta.discourse.org/u/nordize)
#### Post date: [March 23, 2017, 1:36pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/1 "2017-03-23T13:36:02Z")

</div>

I’m trying to create users manually (I have a few reasons for doing this). I tried various combinations of

- `User.create()`
- `User.new()`
- setting the `active:true` or `approved:true` or `approve_by_id:1` or `password:'non-empty-string'` in the arguments of the above
- calling `.approve(<user>, true)` ← according to [user.rb#L270](https://github.com/discourse/discourse/blob/e8fc8f0bb644f97d0adb535fdfbb352bce26c2a1/app/models/user.rb#L270) it should trigger an email?
- calling `.activate()`

While new users are created fine, no email is ever sent to the new user. I can skip the `.activate()` step and then go to the GUI and click on the `Send activation email` which does send them an email to activate their account. Getting an activatin email is still not great, because the user does not know their password and involves a lot of mouse clicking. I would then either have to send them a separate email with their password, or edit the activation email to tell them to change their password … neither of those is really great.

What I really want is to send them the _“Welcome, please choose a password”_ email that has a link taking them straight to the screen where they choose a new password.

How can I trigger that email from the console?

---

<div class="post-metadata">

### Author: ![nordize](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@nordize](https://meta.discourse.org/u/nordize)
#### Post date: [March 23, 2017, 2:06pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/2 "2017-03-23T14:06:25Z")

</div>

Correction: If I enable the `must approve users` options in Settings then an email is sent, but it is an activation email (similar to what I can generate by clicking “Send activation email”), whereas what I’d like is an email that takes them directly to the screen for choosing a password

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [March 23, 2017, 2:34pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/3 "2017-03-23T14:34:00Z")

</div>

I guess you can use Invites feature for this functionality. Invited user can choose their password (optional) while accepting the invitation.

---

<div class="post-metadata">

### Author: ![nordize](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@nordize](https://meta.discourse.org/u/nordize)
#### Post date: [March 23, 2017, 6:48pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/4 "2017-03-23T18:48:44Z")

</div>

I want to do it from the console with predefined usernames, and force users to only chose a password (I don’t want them to choose the username, the setting `username change period` is set to 0). I don’t think invites help me in this context …

Is there no way to trigger a “choose a password” email from the console?

I tried to to use `Jobs.enqueue()`, similarly to how it’s used in `User.send_approval_email()` [here](https://github.com/discourse/discourse/blob/e8fc8f0bb644f97d0adb535fdfbb352bce26c2a1/app/models/user.rb#L1022) but I failed at generating an email hash

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [March 23, 2017, 8:36pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/5 "2017-03-23T20:36:42Z")

</div>

You can do the same as what happens when they click “Send password reset email” in their preferences:

> <https://github.com/discourse/discourse/blob/master/app/controllers/session_controller.rb#L248-L249>

---

<div class="post-metadata">

### Author: ![nordize](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@nordize](https://meta.discourse.org/u/nordize)
#### Post date: [March 26, 2017, 6:17pm UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/6 "2017-03-26T18:17:01Z")

</div>

@neil awesome! Thanks. That was the pointer I needed.

I wanted the “choose a password” email (rather than “password reset” which is confusing for a new user), so I replaced `type: :forgot_password` with `type: :account_created` … job done.

For anyone looking for the full command list:

```plaintext
rails c
u = User.new({username: 'foo', email: 'foo@domain.com', name: 'Foo', trust_level: 1, password: SecureRandom.hex});
u.activate();
u.approve(1); # approved by user id 1, which is normally the first admin account
t = u.email_tokens.create(email: u.email);
Jobs.enqueue(:critical_user_email, type: :account_created, user_id: u.id, email_token: t.token);

```

The option `must approve users` is disabled in Settings.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 19, 2019, 4:32am UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/7 "2019-05-19T04:32:16Z")

</div>



---

<div class="post-metadata">

### Author: ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)
#### Post date: [May 19, 2019, 10:16am UTC](https://meta.discourse.org/t/welcome-email-not-sent-when-adding-user-from-console/59765/8 "2019-05-19T10:16:13Z")

</div>


