# Additional email address per user account support

**URL:** https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847
**Category:** Feature
**Created:** [March 24, 2017, 2:14pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847 "2017-03-24T14:14:41Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![jmana9](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmana9/32/111273_2.png) [@jmana9](https://meta.discourse.org/u/jmana9)
#### Post date: [July 16, 2018, 6:47pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/25 "2018-07-16T18:47:09Z")

</div>

I see the same thing on v2.1.0.beta2 +266; the field appears for Secondary Emails, but no apparent way to add one on the user or admin side.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [July 17, 2018, 2:47am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/26 "2018-07-17T02:47:26Z")

</div>

That PR doesn’t add the UI for adding a secondary email so you’ll not be able to do so yet.

---

<div class="post-metadata">

### Author: ![jmana9](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jmana9/32/111273_2.png) [@jmana9](https://meta.discourse.org/u/jmana9)
#### Post date: [July 17, 2018, 3:05pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/27 "2018-07-17T15:05:27Z")

</div>

Gotcha. Is there an estimate for a release date for the UI portion?

---

<div class="post-metadata">

### Author: ![Thanatermesis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thanatermesis/32/119521_2.png) [@Thanatermesis](https://meta.discourse.org/u/Thanatermesis)
#### Post date: [July 18, 2018, 5:59pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/28 "2018-07-18T17:59:57Z")

</div>

Im not sure if im in the correct topic, let me explain the case:

Actually I’m having difficulties to whitelist the domain in [http://matrix.spfbl.net/en/138.68.75.234](http://matrix.spfbl.net/en/138.68.75.234)

Basically, they attempts to send an email to [postmaster@forum.example.com](mailto:postmaster@forum.example.com), but this address doesn’t exist and is not managed (I used this setup [Configure direct-delivery incoming email for self-hosted sites with Mail-Receiver](https://meta.discourse.org/t/straightforward-direct-delivery-incoming-mail/49487) ), so it is received as “rejected” (but seems like it is cut?)

How i can make it to be a real address, or to be forwarded to a specific “admin of the forum” address? I would need to add an additional address to my user profile?

---

<div class="post-metadata">

### Author: ![notriddle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/notriddle/32/133055_2.png) [@notriddle](https://meta.discourse.org/u/notriddle)
#### Post date: [July 19, 2018, 1:51am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/29 "2018-07-19T01:51:00Z")

</div>

> [@Thanatermesis](#):
>
> Im not sure if im in the correct topic, let me explain the case:

It’s definitely not. [@staff](https://meta.discourse.org/groups/staff) please move this into its own topic, or into the Staightforward direct-delivery one.

> [@Thanatermesis](#):
>
> How i can make it to be a real address, or to be forwarded to a specific “admin of the forum” address? I would need to add an additional address to my user profile?

No. There are basically two ways you could fix this.

## Forwarding

You could have a separate email service forward into your Discourse mail receiver, so that nobody ever sees your forum’s IP address directly and it doesn’t matter if it’s on a DNSBL or not.

For example, [https://forum.bors.tech](https://forum.bors.tech) uses Mailgun. There is a mail-receiver running on there; port 25 is even open to the public. But my reply-to address is set to `reply+%{reply_key}@bors.tech`, with no `forum.` in the domain name, and Mailgun has a route that forwards `reply+.*@bors.tech` to `reply@forum.bors.tech`.

## Add a group

You can configure a Group in Discourse to receive emails to [postmaster@forum.example.com](mailto:postmaster@forum.example.com). Add only staff to it.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [August 10, 2018, 9:28pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/30 "2018-08-10T21:28:35Z")

</div>

> [@tgxworld](#):
>
> you’ll not be able to do so yet.

Not at all or is there a way via CLI?

---

<div class="post-metadata">

### Author: ![LeoMcA](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leomca/32/87233_2.png) [@LeoMcA](https://meta.discourse.org/u/LeoMcA)
#### Post date: [August 13, 2018, 6:14pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/31 "2018-08-13T18:14:48Z")

</div>

Yep, open the rails console with `rails c`, and do something like this:

```ruby
UserEmail.create!(user: User.find_by_username("user1"), email: "user1@example.com")

```

---

<div class="post-metadata">

### Author: ![Daniel\_Lopes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/daniel_lopes/32/374589_2.png) [@Daniel\_Lopes](https://meta.discourse.org/u/Daniel_Lopes)
#### Post date: [December 4, 2018, 10:27pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/32 "2018-12-04T22:27:12Z")

</div>

> [@LeoMcA](#):
>
> ```plaintext
> UserEmail.create!(user: User.find_by_username("user1"), email: "user1@example.com")
> 
> ```

@LeoMcA thank you so much for the work on this change. It made possible for my company to integrate our products with the community without having to deal with merging or deleting stuff.

---

<div class="post-metadata">

### Author: ![Jim.Morrison](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jim.morrison/32/162161_2.png) [@Jim.Morrison](https://meta.discourse.org/u/Jim.Morrison)
#### Post date: [February 12, 2019, 10:27pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/33 "2019-02-12T22:27:10Z")

</div>

> [@LeoMcA](#):
>
> Yep, open the rails console with `rails c` , and do something like this:
> 
> ```plaintext
> UserEmail.create!(user: User.find_by_username("user1"), email: "user1@example.
> 
> ```

Does remove the email stated in the rails console or the entire user? My goal is to only remove the secondary email associated with the user. Thanks in advance.

---

<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: [February 15, 2019, 6:04pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/34 "2019-02-15T18:04:40Z")

</div>

Where did you get that `create!` would delete something? 😉

Here’s how to delete all secondary emails for a user

```ruby
UserEmail.where(user_id: 1234, primary: false).destroy_all

```

---

<div class="post-metadata">

### Author: ![Jim.Morrison](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jim.morrison/32/162161_2.png) [@Jim.Morrison](https://meta.discourse.org/u/Jim.Morrison)
#### Post date: [February 15, 2019, 6:18pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/35 "2019-02-15T18:18:46Z")

</div>

Thanks I’ll give it a shot!

---

<div class="post-metadata">

### Author: ![Jim.Morrison](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jim.morrison/32/162161_2.png) [@Jim.Morrison](https://meta.discourse.org/u/Jim.Morrison)
#### Post date: [February 15, 2019, 6:23pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/36 "2019-02-15T18:23:58Z")

</div>

Worked great. Thanks for the help Regis!

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [February 15, 2019, 9:06pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/37 "2019-02-15T21:06:15Z")

</div>

@zogstrip could you please add secondary email address to the user export, like you did for staged? That was super handy! [Feature request: add STAGED field to export user list to csv](https://meta.discourse.org/t/feature-request-add-staged-field-to-export-user-list-to-csv/69580)

It’ll be helpful for admins to be able to see what’s in this field and deal with it as needed. For my use case, I would like to see who has a secondary email set and remove it so I don’t [run into trouble anymore with SSO and users with secondary emails](https://meta.discourse.org/t/rake-task-for-merging-users/89086/40).

---

<div class="post-metadata">

### Author: ![sizeof](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sizeof/32/131954_2.png) [@sizeof](https://meta.discourse.org/u/sizeof)
#### Post date: [February 20, 2019, 10:31am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/38 "2019-02-20T10:31:41Z")

</div>

This was very useful!  
I needed to replace all staged users email addresses with another domain/tld, but keep the originals as secondary email.  
This allows mbox importing script to recognize them from the secondary email but discourse sends notifications on the primary email.

Hope someone will find it useful.

```plaintext
UserEmail.where("email LIKE '%@domain.tld'").where(primary: true).find_each do |ue|
    new_mail = ue.email.gsub(/@.+$/, '@newdomain.tld')
    next if UserEmail.exists?(email: new_mail)
    UserEmail.where(email: ue.email).update_all(email: new_mail)
    UserEmail.create!(user_id: ue.user_id, email: ue.email)
end
```

---

<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: [February 27, 2019, 9:14am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/39 "2019-02-27T09:14:39Z")

</div>

Sure thing and while in there I also fixed a bug with the `escape_comma` method

[https://github.com/discourse/discourse/commit/326d892f5e584212768d090d8462e3a9430bbda2](https://github.com/discourse/discourse/commit/326d892f5e584212768d090d8462e3a9430bbda2)

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [April 17, 2019, 9:17pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/41 "2019-04-17T21:17:42Z")

</div>

Much as I like the idea of the secondary email address, I am finding it to be a burden when managing my community and wishing there were a way to disable it.

> [@zogstrip](#):
>
> Here’s how to delete all secondary emails for a user
> 
> ```plaintext
> UserEmail.where(user_id: 1234, primary: false).destroy_all
> 
> ```

am I right that to wipe out all secondary emails I would use the following?

```plaintext
UserEmail.where(primary: false).destroy_all

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 18, 2019, 3:19am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/42 "2019-04-18T03:19:36Z")

</div>

Why specifically is it a “burden”?

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [April 18, 2019, 2:50pm UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/43 "2019-04-18T14:50:24Z")

</div>

It is a burden for a few circumstances that keep coming up that take up too much time and brain space to figure out:

- we invite people to join using one address, creating a staged user account, but then they actually end up joining using another email address. Or we find they already had another account using a different email.
- we invite people with dormant accounts to come back, and instead of logging in with their existing account they create a new account with another email address

In these cases, we merge the accounts and then change the email address to the newer one that the people want to use. We use WordPress SSO and change the email address in WordPress, which then updates it in discourse. If the email address we want to change it to is already contained in the secondary email field in discourse for the user, then we have to delete it first otherwise this step fails silently.

We have also had cases of people coming to create a new account after we merged their user accounts, using the secondary email address. This does not work with our current SSO setup and fails silently.

So… there are some technical challenges to work out, and I’m not sure it’s a priority on your end and I know it’s a backburner priority on my end to improve how wordpress and discourse play with each other. I know I am also pushing the envelope in how staged users are intended to be used.

In the meantime I’d be happy if I could just disable the functionality. If it’s not possible, I will just get in the habit of also clearing the secondary email every time I merge users.

---

<div class="post-metadata">

### Author: ![jongalloway](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jongalloway/32/108133_2.png) [@jongalloway](https://meta.discourse.org/u/jongalloway)
#### Post date: [May 13, 2019, 5:46am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/44 "2019-05-13T05:46:55Z")

</div>

Sorry if I’m in the wrong place, but I’m trying to add a secondary e-mail address to my existing account and can’t find a way to do it in the web interface. The best thing I find is a forum with a bunch of Ruby code and what even is happening.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [May 13, 2019, 5:48am UTC](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847/45 "2019-05-13T05:48:30Z")

</div>

That’s right, the secondary email is only set if accounts are merged.

You’re going to need to resort to the rails console if you want to add a secondary email address.

[Previous page](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847.md?page=1)

[Next page](https://meta.discourse.org/t/additional-email-address-per-user-account-support/59847.md?page=3)
