# Allow for email re-writing to solve the additional email address?

**URL:** https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892
**Category:** Feature
**Created:** [Março 11, 2017, 7:43pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892 "2017-03-11T19:43:00Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Março 11, 2017, 7:43pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/1 "2017-03-11T19:43:00Z")

</div>

Continuing the discussion from [Straightforward direct-delivery incoming mail](https://meta.discourse.org/t/straightforward-direct-delivery-incoming-mail/49487):

Over in `Two emails for one user` the debate in:

> [@Two emails for one user](https://meta.discourse.org/t/two-emails-for-one-user/16328/35):
>
> Are we supporting 2 or {n} emails per user for that amount of work?

Its pretty much settled on 2 emails. I think that’s best, but there will still be cases where we need to handle more.

I wonder if there could be a lookup table added to this discourse email processor which would have a rewrite table.

The idea is that incoming emails would be re-written, much like [G-Suite Routing Rules](https://support.google.com/a/answer/6297084) so that by the time an email got to discourse, `johndoe@example.org` could be “from” a registered user in the name of `jdoe@example.com`

I’d be interested in getting the dev for this done but would need some pointers.

- Would a PR for this be welcome?
- Where would a loop like this best fit?

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [Março 12, 2017, 9:51pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/2 "2017-03-12T21:51:37Z")

</div>

I don’t understand why you would want to “rewrite” e-mail addresses, especially the from address. That’s going to be more code than just matching e-mail addresses to users, because not only do you have to do the matching (you need to map from address to an account, to get the “canonical” address) you then also have to write the code to mangle the incoming e-mail.

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Março 12, 2017, 10:00pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/3 "2017-03-12T22:00:38Z")

</div>

If discourse were going to {n} extra emails route then sure, this wouldn’t be needed.

However, solving this for primary+secondary is going to fix the issue for ~90%+ of the use cases, and I’m just glad to see things going.

I’ve already got a project that re-writes outgoing emails (looking for a slug & replacing it with a custom value) so it’s not going to be that big of a project to re-use that here.

In two of the 4 forums I run, all users are members, but I don’t know them all personally and it’s hard to get them to reply to “would you please stop sending from the wrong address” requests. They are just annoyed their message didn’t post, and don’t understand that Apple Mail is really bad about ensuring new messages go out from the right address.

It’s going to be much less work on me to just say screw it, and know that user X might reply from A,B,C, or heck, even D and keep a table to match.

If there’s a good spot for it within Discourse, perhaps in the mail receiver:

[GitHub - discourse/mail-receiver · GitHub](https://github.com/discourse/mail-receiver)

I’d have someone on my team create this mapping component.

EDIT.. it says right here I could use a ` add a pre-delivery milter,`

[https://github.com/discourse/mail-receiver#customised-postfix-configuration](https://github.com/discourse/mail-receiver#customised-postfix-configuration)

I think I’ll try that.

---

<div class="post-metadata">

### Author: ![mpalmer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mpalmer/32/45740_2.png) [@mpalmer](https://meta.discourse.org/u/mpalmer)
#### Post date: [Março 12, 2017, 10:07pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/4 "2017-03-12T22:07:11Z")

</div>

Yeah, arbitrary from address rewriting isn’t going to go into the generic mail-receiver. It’s far, far too niche. On the other hand, forking it and layering your own logic on top isn’t hard – it’s built that way, because that’s how our internal mail handling works on discourse.org-hosted forums. The Dockerfile moves the original script out of the way, and puts a new one in its place that loads the original script and just replaces the `post_email` method).

Even then, though, you’d probably be better off contributing n-email support into Discourse proper. I don’t think n-email support is something that we’d not accept a PR for, it’s just something that we’re not going to put together ourselves.

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Março 12, 2017, 10:10pm UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/5 "2017-03-12T22:10:33Z")

</div>

Thank Matt, I think I have a way forward I can understand well enough to take on.

The people I have at my disposal can get a postfix milter done easily, I don’t know what n-email support within discourse core would take, but I assume if it were easy-enough, it’d be done already. 😉

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Abril 20, 2017, 12:56am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/6 "2017-04-20T00:56:26Z")

</div>

It looks like this:

> [@](#):
>
> Continuing the discussion from [Discourse Version 1.9](https://meta.discourse.org/t/discourse-version-1-9/61289):
> 
> Forward multiple emails to Discourse, staging unknown emails as new users and attaching matching existing users by email

Will solve the problem nicely. Looking forward to it.

---

<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: [Abril 20, 2017, 1:17am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/7 "2017-04-20T01:17:08Z")

</div>

That is totally unrelated to this topic. That is about forwarded email chains.

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Abril 20, 2017, 1:18am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/8 "2017-04-20T01:18:45Z")

</div>

If an incoming email which doesn’t match is staged, and can be mapped to a current user.. that’ll be just fine for my need.

I’ll redirect & tell the person not to use the unrecognized email address any more. Typically, they only need to be told once, and they’ll either stop, or we’ll change their primary email address.

---

<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: [Abril 20, 2017, 2:10am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/9 "2017-04-20T02:10:59Z")

</div>

As long as you’re clear _that_ feature is about taking a giant forwarded email chain and forwarding it to Discourse to **create a topic** and stage the users **based on the giant forwarded email chain**.

Basically it is

> take this giant email with dozens of participants and turn it into a sane Discourse topic for me automagically

clear?

---

<div class="post-metadata">

### Author: ![watchmanmonitor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/watchmanmonitor/32/430970_2.png) [@watchmanmonitor](https://meta.discourse.org/u/watchmanmonitor)
#### Post date: [Abril 20, 2017, 2:12am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/10 "2017-04-20T02:12:07Z")

</div>

ok, If that feature gets extended to any given email which comes in from an unknown address, it’ll be nice.

---

<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: [Abril 20, 2017, 2:12am UTC](https://meta.discourse.org/t/allow-for-email-re-writing-to-solve-the-additional-email-address/58892/11 "2017-04-20T02:12:22Z")

</div>

Nope that is not the plan.
