Getting E-Mails from inactive users

AI-generated summary

fefrei reported an issue where inactive users in a staged Discourse installation for a yearly event were rejected when sending emails, receiving an Email::Receiver::InactiveUserError. zogstrip explained that this error occurs when a user is neither activated nor staged, suggesting that marking users as staged would resolve the issue. When fefrei asked if existing inactive users could be marked as staged via the admin UI, zogstrip clarified that this requires using the Rails console or a SQL query, confirming that users would revert to normal status upon logging in. fefrei later noted a bug where users who logged in via SSO remained staged even after becoming active. zogstrip acknowledged the potential SSO-related issue and investigated. Meanwhile, fefrei shared a Rails console command to update inactive users: User.where({ active: false }).update_all({ staged: true }). zogstrip suggested a more concise syntax. Finally, zogstrip pushed a fix for the SSO staging issue, which fefrei confirmed was successful after deployment.

I’m using incoming mail support for group messaging with staged users.

This works fine if the address the message is coming from is new. However, I am re-purposing a Discourse installation for a yearly event, and some old users are stuck with an inactive accounts they can no longer log in to.

When such a user sends a mail to Discourse, they are rejected with Email::Receiver::InactiveUserError.
What’s the best method to prevent this issue? Would replacing the mail address of the inactive accounts work?

Any thoughts here @zogstrip?

The InactiveUserError happens only when the user is not activated and not staged. If you want your users to be able to send emails in, you will have to either activate their account or mark them as staged.

Can I mark existing, inactive users as staged? Would that have any side effects?

Other than enabling them to send emails in, none :wink:

How can I do that, then? The admin UI does not offer this option.

Will they return to normal if they ever log in?

You’ll have to use the rails console or run a SQL query.

Yes.

Hm, it looks like this doesn’t work.

I had a non-active, staged user (that had been disabled via the interface and staged via Rails). After the user logged in (via SSO), he had to confirm has address, became active and could log in, but is still staged:

Hmm, it might not unstage when using SSO. Having a look.

Thanks a lot!

In the meantime, for anyone who wants to try the same approach, here’s what I ran on the rails console (rails c inside the container):

User.where({ active: false }).update_all({ staged: true })

You can do slightly shorter :wink:

User.where(active: false).update_all(staged: true)

I’ve given up understanding Ruby’s syntax a long time ago – even my version took many tries to be correct. Thanks for the shorter version :wink:

Just pushed a fix :helicopter:

https://github.com/discourse/discourse/commit/874c18cbc1c4768412cfe9ca08f416295f112c8b

After a journey into tests-passed lands, I can confirm this is fixed. Thanks a lot!