Change staff email address from console

:bookmark: This guide describes how to change a staff member’s email address from the console using the Rails console. It applies to situations where an administrator needs to update an email without confirmation from the old address.

:person_raising_hand: Required user level: System Administrator

:warning: Console access required

In Discourse, for enhanced security, staff members must confirm changes to their email addresses from both the new and old email addresses.
However, this creates a problem when a staff member loses access to their old email address and wants to update their email address. This guide provides steps to change the email address via the console without needing confirmation from the old email.

:information_source:These commands can also be used to force a change in a user’s email address and override the need for them to confirm by clicking on the validation email

Accessing the console

Connect to your Droplet via SSH, or use Putty on Windows:

ssh root@192.168.1.1

Replace 192.168.1.1 with the IP address of your Droplet.

Switch to your Discourse folder:

cd /var/discourse

Enter the container:

./launcher enter app
# or
./launcher ssh app

Access Rails Console:

rails c

Changing the email address

To personalise these for your user, input your information here:


               or

Then run these commands (each on a separate line)

u = User.find_by_id(=UserID=)

               or

u = User.find_by_username("=Username=")

u.email = "=EMAIL="

:information_source: If a user has reached the limit for bounced emails (i.e., their bounce score has exceeded the threshold set by your Discourse site), creating a new email token with u.email_tokens.create(email: u.email) will not have any impact, and you will need to first Reset their Bounce Score before proceeding.

u.email_tokens.create(email: u.email)
u.save!

That’s it, your email address should be updated, and you should be able to login with your new email.

Last edited by @SaraDev 2024-11-14T21:28:15Z

Check documentPerform check on document:
29 Likes