Additional email address per user account support

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

1 Like

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

1 Like

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

Basically, they attempts to send an email to postmaster@forum.example.com, but this address doesn’t exist and is not managed (I used this setup Straightforward direct-delivery incoming mail ), 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?

It’s definitely not. @staff please move this into its own topic, or into the Staightforward direct-delivery one.

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 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. Add only staff to it.

4 Likes

Not at all or is there a way via CLI?

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

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

@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.

7 Likes

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.

Where did you get that create! would delete something? :wink:

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

UserEmail.where(user_id: 1234, primary: false).destroy_all
6 Likes

Thanks I’ll give it a shot!

Worked great. Thanks for the help Regis!

1 Like

@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

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.

3 Likes

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.

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
3 Likes

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

7 Likes

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.

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

UserEmail.where(primary: false).destroy_all

Why specifically is it a “burden”?

2 Likes

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.

5 Likes

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.

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.

5 Likes

Howdy Jon!

You are certainly in the right place. Is this for dotnetfoundation? Can you email team@discourse.org, we will get it sorted for you!

6 Likes