# Bulk Update Email of Users

**URL:** https://meta.discourse.org/t/bulk-update-email-of-users/210840
**Category:** Support
**Created:** [December 2, 2021, 6:52am UTC](https://meta.discourse.org/t/bulk-update-email-of-users/210840 "2021-12-02T06:52:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![asifaly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/asifaly/32/241999_2.png) [@asifaly](https://meta.discourse.org/u/asifaly)
#### Post date: [December 2, 2021, 6:52am UTC](https://meta.discourse.org/t/bulk-update-email-of-users/210840/1 "2021-12-02T06:52:03Z")

</div>

Hi, I am on the latest version of discourse. I have changed the domain from `subdomain1.domain1.com` to `subdomain1.domain2.com`.

My user emails have also changed from `@domain1.com` to `@domain2.com`.

I found a [post](https://meta.discourse.org/t/how-can-i-bulk-remap-update-user-email-addresses/56519) to create RAKE test to do this. But this post is from 2017.

I understand we need to look at UserEmail.email now for the emails. Could you please suggest how to modify this rake task to cater to the table changes in discourse latest version.

---

<div class="post-metadata">

### Author: ![asifaly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/asifaly/32/241999_2.png) [@asifaly](https://meta.discourse.org/u/asifaly)
#### Post date: [December 9, 2021, 11:14am UTC](https://meta.discourse.org/t/bulk-update-email-of-users/210840/2 "2021-12-09T11:14:42Z")

</div>

I managed to solve this by directly accessing the DB from the docker instance

```plaintext
cd /var/discourse
./launcher enter app
su discourse
psql discourse

```

In the postgres console, run the following query

```plaintext
UPDATE user_emails
SET email = REPLACE (email, '@olddomain.com', '@newdomain.com');

```

Once this is done, the users can do a forgot password with their new email address and create a new password.

---

<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: [January 8, 2022, 11:14am UTC](https://meta.discourse.org/t/bulk-update-email-of-users/210840/3 "2022-01-08T11:14:42Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
