Change user's email without verification

AI-generated summary

Users are seeking ways to change a user’s email address in Discourse without requiring verification, particularly for admin use cases. carlokok initiates the discussion, asking if admins can bypass email verification. elijah suggests using the Rails console to directly update the email via User.find_by(...).update(...). JagWaugh references a meta topic recommending deactivating, changing, then reactivating the user — though this still triggers a confirmation email. skodali reports that even this method still requires confirmation and asks if it’s possible via API for bulk updates. schungx provides updated console commands targeting the UserEmail model: UserEmail.find_by(email: "old@example.com").update(email: "new@example.com"). However, Iceman encounters a NoMethodError, likely because the email wasn’t found — possibly due to typos or changes in schema. mint_saxon confirms the command works if the email matches exactly. codinghorror suggests server time drift may cause expired verification links. Admins also report rate-limiting errors when attempting email changes, even after a single attempt. The consensus leans toward using the Rails console with UserEmail for direct, unverified updates — but accuracy in email matching is critical. API-based solutions for bulk changes remain unconfirmed.

Maybe I’m missing something obvious, but I cannot find it. As an admin, can I change someone’s email address without them having to verify it?

Off-hand, I’d guess something like this would work:

cd /var/discourse
./launcher enter app
rails c
User.find_by(email: "chowder@mmmm.fooo").update(email: "bisque@soup.mmmm")
exit
exit

That’s console access, obviously.

I vaguely recall another topic here about this exact situation; try some searches.

Try this, the verification mail goes out, but they don’t have to respond to it:

Too late for me to edit that now, but it should be deactivate, change, reactivate iirc.

No problem I made it a wiki.

I am a new discourse user and I ran into the same issue. When I try the same approach (deactivate the user, update the email address, and then activate the user) it sending an email to confirm and it is only updating the email address after clicking the confirm email link. Is there a way to avoid this? I am using the API to do all the three actions.

There has been a change in the way emails are stored in the database.

The following commands should work:

cd /var/discourse
sudo ./launcher enter app
rails c

UserEmail.find_by(email: "oid@example.com").update(email: "new@example.com")

This will work fine but I am trying to do this via API as I will have to update multiple email addresses on a daily basis. Is it possible to do this via API?

Massiva Necromanzia, sì, ma sto riscontrando un problema simile e, dato che la ricerca mi ha portato qui, potrebbe essere utile aggiornare i comandi in base a questa esperienza.

La mia situazione è la seguente:

  • Alcuni dei miei utenti hanno provato a cambiare il loro indirizzo e-mail principale.

  • Affermano che non ha funzionato. Hanno ricevuto un’e-mail per la conferma, ma cliccando sul link ricevono sempre un messaggio “Scaduto/Non funziona”.

  • Io, come Amministratore, vado a cambiare quell’e-mail modificando il loro profilo.

  • Ora l’e-mail principale risulta in “in attesa di conferma/verifica”.

  • Gli utenti non ricevono alcuna e-mail di conferma.

  • Non importa quante volte premo l’opzione “reinvia e-mail di convalida/conferma” sul loro profilo, non viene inviata (ho verificato nella sezione Amministratore/E-mail: non c’è nessuna e-mail in uscita relativa a ciò. Ironia della sorte, se clicco per inviare loro l’e-mail di “reset della password”, quella viene inviata).

Il fatto è che, se uno di questi utenti cancella i cookie ecc., non potrà più accedere al proprio account (sta succedendo proprio ora). Quindi ho provato questo:

Ma ottengo NoMethodError: undefined method `update' for nil:NilClass. Quindi forse i campi sono cambiati di nuovo negli ultimi due anni? :stuck_out_tongue:

Qualsiasi aiuto è benvenuto.

PS: Inoltre, se provo a cambiare l’e-mail con un altro indirizzo o con quello vecchio, ora io (amministratore) ricevo il messaggio “Hai eseguito questa azione troppe volte. Riprova più tardi”. Quanto tempo deve passare per “più tardi” e perché l’Amministratore è soggetto a limiti di frequenza quando cambio le e-mail, se l’ho fatto solo una volta? Probabilmente ho fatto qualcosa di sbagliato senza accorgermene :facepalm:

Quindi la consegna delle email funziona, forse l’orario del server è sbagliato o non corretto? Se l’orario del server è errato, questo può accadere.

Funziona per me! Se stai ancora riscontrando questo problema (o per chiunque altro trovi questo argomento :sweat_smile:), penso che quell’errore si verifichi se UserEmail.find_by(email: "oid@example.com") non restituisce nulla. Vale la pena verificare che l’indirizzo email corrisponda esattamente.