How to bulk-disable digests for some users?

Is there a way to disable digest emails from some users via the Rails console like in the example code below? I’m trying to read in from a list and turn off the digest emails if that email address is in the list. The line u.user_option.email_digests = false doesn’t seem to change the setting on the user settings page. (I tried it on just my own user account to test it and haven’t run the rest of the code yet.)

# rails c
users = { |u| > 0 }
processed_users = []
txt ='no_email_digest_list.txt').read
lines = txt.split("\n")
h = { |x| [x.strip, true] }.to_h

users.each do |u|
  if h.has_key?
    u.user_option.email_digests = false
    processed_users <<
    # puts # dry run

puts "updated #{processed_users.count} users"

This should be enough

cd /var/discourse
./launcher enter app
rails c
SiteSetting.disable_digest_emails = true

I’m only disabling it for about 1,500 accounts at the moment, not all the users. Is there a way to only disable it for users whose email addresses appear in a text file?

I couldn’t figure out why it wouldn’t work either, but it’s because you need to save u.user_option, not u!

Thanks, that worked.

This isn’t exactly related, but it’s another email problem – does anyone know why my new install isn’t sending emails for private messages or forum replies? It’s sending some types of emails – even a digest to me (because I’m the only user who has them set for every 30 minutes).

In the screenshot below, we’ve sent several private messages back and forth, but none of them appear to have been sent out by Discourse. It was working before the user import. I had these settings in the import script but have already reverted them. The users all do have emails enabled for private messages and mentions.

    SiteSetting.disable_emails = "non-staff"
    SiteSetting.allow_index_in_robots_txt = nil
    SiteSetting.login_required = true

It appears that some of the emails finally sent, about 5 hours after being posted. I found the /sidekiq route, and it looks like there are many jobs queued after the import, so maybe that was the problem.

Thanks again for the help.


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