Too many user emails domains not working lead to mailgun domain disabled: what to do?


My forum has a lot of imported users that have a specific email domain that doesn’t work anymore.
A few thousand users have such an email address.

It was not an issue until now, but I increased suppress digest email after days value, and my forum sent a lot of digest emails, including to a lof of users having non-working email domains.

It led to too many bounces and mailgun disabled my domain.

What should I do with these accounts to prevent this and fix my issue? A lot of these accounts belong to legit users that didn’t come back to the forum yet. There are not necessarily abandoned accounts.

Because of this issue, users can’t register to the forum until it is fixed.

1 Like

Check out Handling bouncing e-mails


For some reason I didn’t find this topic using the search… I guess I panicked! :sweat_smile:

Thanks you very much for your fast answer!


But if there are a zillion email addresses like bademail.domain, maybe what you want to do is something like

rake posts:remap['bademail.domain', 'no-email.invalid']

as described in Replace a string in all posts. That will make all of those email addresses such that Discourse won’t send to them. Another good solution would be something like

bad=User.find_by_email     <some search that will get them all>
bad.update_all(active: false)

and deactivate all of the users with the known bogus email addresses. Not quite sure how to do the first bit off the top of my head, but it should be easy enough to figure out.


Yeah, I thought about doing this to get rid of these email domains.

I notice that a Discourse method creates @no-email.invalid emails:

And in the importer base, it uses @email.invalid which is slightly different:

  1. Are these two different “dummy domains” both ignored when Discourse must send emails?

  2. Should I replace my non-working domain with @no-email.invalid or @email.invalid, or it doesn’t matter?

@pfaffman, I’m not sure to understand why I should remap in posts instead of changing the user emails:thinking: These email addresses aren’t in posts, unless I’m missing something.

If it is a recommended way, I’d just like to replace my addresses in each profile by @no-email.invalid or @email.invalid. I can figure out how to do this, I just wonder which “fake” domain to use.

1 Like

I’m fairly certain that posts:remap remaps that domain across all tables, but they had to put it in some class.

You could also just write your own replacement in the UserEmails table (or whatever it’s called).

I’m fairly certain that whatever.invalid will tell The World that it’s an invalid address and it won’t try to send it.


Neat. So I guess this would do the trick?

User.find_each do |u|
	if ""
		u.update(email: SecureRandom.hex + "@email.invalid")
1 Like

I think I might

UserEmail.where("email like ''").each do |e|
   e.update(email: SecureRandom.hex + "@email.invalid)

Yours could work too, but Im’ not sure if the User model got updated to be able to do a after they moved emails to another model/table.


I tried my script just to see if it was returning the target email addresses and it works.

Your script should be faster than mine since you use a query to select specific email domains instead of looping through all the users.

Thank you very much for your help :+1:


Ooops. Here’s the remap I meant. It’s just

  discourse remap old new

See Change the domain name or rename my Discourse?.

I think that the above would work, but the UserEmails solution is probably a tiny bit better.


Thank you. This is the one I used.
More than 5000 users of a total of 17000 users had such email domains. No wonder the number of bounces when I increased suppress digest email after days


This is special handling by Discourse for anything ending in .invalid, which is a reserved TLD.


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