# Should importers import users with invalid email addresses by default?

**URL:** https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424
**Category:** Development
**Created:** [4 באוקטובר,‏ 2017,‏ 8:31pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424 "2017-10-04T20:31:51Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [4 באוקטובר,‏ 2017,‏ 8:31pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/1 "2017-10-04T20:31:51Z")

</div>

Re-running an import with a bunch of invalid emails is a drag since it has to re-try adding each block of 1000 users if one of them is bad.

I don’t see a down side to importing users with bogus email addresses with a random one rather than throwing an error and think that all importers would benefit from creating those users rather than have their messages owned by @system. Is there something I’m missing?

Should I add something like this to `base.rb`?

```plaintext
          unless opts[:email].match(EmailValidator.email_regex)
            opts[:email]= "invalid#{SecureRandom.hex}@no-email.invalid"
          end

```

Arguably it should still print a warning. . .

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [4 באוקטובר,‏ 2017,‏ 9:48pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/2 "2017-10-04T21:48:22Z")

</div>

Sounds like a good idea!

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [5 באוקטובר,‏ 2017,‏ 4:34am UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/3 "2017-10-05T04:34:05Z")

</div>

Sure, go ahead and submit that, but I would store the original email in a custom field or something in that case.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [5 באוקטובר,‏ 2017,‏ 2:07pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/4 "2017-10-05T14:07:06Z")

</div>

> [@sam](#):
>
> I would store the original email in a custom field or something in that case.

I would too, but I was too lazy to figure out how to add a custom field. Thanks for the push; I’ll figure it out. The tension between getting an import job done and making the code better is high.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [5 באוקטובר,‏ 2017,‏ 9:44pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/5 "2017-10-05T21:44:05Z")

</div>

> [@sam](#):
>
> Sure, go ahead and submit that, but I would store the original email in a custom field or something in that case.

Done. Thanks for the push.

[https://github.com/discourse/discourse/pull/5224](https://github.com/discourse/discourse/pull/5224)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [1 במאי,‏ 2018,‏ 10:14pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/6 "2018-05-01T22:14:14Z")

</div>

Hey, @zogstrip (who accepted the PR above), it looks like something has happened to the email validator (?) such that it no longer thinks that no-email.invalid is a valid domain, so now importers claim to be producing accounts with the new bogus email, but in fact, are not.

At least that’s what it looks like. I re-run an importer and get the same “creating with bogus email address” for the same names over and over. Or maybe I’m doing something silly.

> <https://github.com/discourse/discourse/blob/main/script/import_scripts/base.rb#L307>

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2 במאי,‏ 2018,‏ 7:13am UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/7 "2018-05-02T07:13:01Z")

</div>

Are you sure the error is on the email? I just tried this on the rails console and it worked fine

```rails
User.create!(email: "invalid#{SecureRandom.hex}@no-email.invalid", username: "random")

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2 במאי,‏ 2018,‏ 12:04pm UTC](https://meta.discourse.org/t/should-importers-import-users-with-invalid-email-addresses-by-default/71424/8 "2018-05-02T12:04:18Z")

</div>

Darn. Apparently I am not.

I know that it silently failed to create those users (because subsequent runs would all claim to create them with the be bogus address) and then when I changed the bogus address to [example.com](http://example.com) it created them. This was on three imports with two different importers.
