# E-mail ontvangen in mail-receiver maar NIET in Discourse?

**URL:** https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235
**Category:** Self-hosting
**Created:** [25 november 2020 om 01:46 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235 "2020-11-25T01:46:48Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan\_N](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryan_n/32/200907_2.png) [@Ryan\_N](https://meta.discourse.org/u/Ryan_N)
#### Post date: [25 november 2020 om 01:46 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/1 "2020-11-25T01:46:48Z")

</div>

This is for an initial install, and I’m not a DNS guru by any means! Here’s where I’m at:

- Outbound email tests are working fine. I’m using MailGun with their recommended “mg” subdomain. I’m sending on port 2525. I do have the MailGun API for webhooks entered in that respective field, in settings (they have THREE API’s–is this the right one??). I also have MX records for the mg subdomain entered in my DNS settings. Mailgun validation check says all is working properly, as does [mail-tester.com](http://mail-tester.com).
- Inbound is configured with a subdomain called “inbound.” If I send an email from a gmail account to fake@inbound.[mydomain].org, I can see that email arrive in the mail-receiver log. If I send, from Discourse, a test email to that same address via Settings \> Email, the email seems to disappear–noting shows up in the Rejected bin. I am using [Straightforward direct-delivery incoming mail](https://meta.discourse.org/t/straightforward-direct-delivery-incoming-mail/49487) for the rest.

Due to other self-inflicted snafu in the setup process, I opted to begin from a clean slate: I deleted my droplet, reinstalled Discourse and am starting all over again. I did _not_ however delete the MailGun account and am actually using the same API webhook as before. Could this be the problem? I _am_ however using a new Discourse-produced API key (the old one, obviously, was vaporized when I deleted the droplet).

The only other think I can think of, is the endpoint in mail-receiver.yml. Mine looks like this: `DISCOURSE_MAIL_ENDPOINT: 'https://inbound.[mydomain].org/admin/email/handle_mail'`

Any thoughts on where the hangup is? (The icing on the cake is that I had it all working at one point not long ago—before I deleted the droplet. I’m a slow learner, apparently 😜). Thanks all!

---

<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: [25 november 2020 om 02:00 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/2 "2020-11-25T02:00:12Z")

</div>

> [@Ryan\_N](#):
>
> The only other think I can think of, is the endpoint in mail-receiver.yml. Mine looks like this: `DISCOURSE_MAIL_ENDPOINT: 'https://inbound.[mydomain].org/admin/email/handle_mail'`

This should be the domain of your forum, not your email. Can you confirm that your forum is not at `inbound.[mydomain].org`? E.g. if meta were using this method, the url would look like this:

```
DISCOURSE_MAIL_ENDPOINT: 'https://meta.discourse.org/admin/email/handle_mail'

```

Also.. this has nothing to do with mailgun, except to make sure to ignore mailgun’s instruction to add MX records for the domain. As per:

> Note: outbound email providers like mailgun may ask you to add MX records pointing to their servers. You want to remove these so the MX records for your forum only point to your forum’s domain name. SPF and DKIM records must still point to your outbound email provider servers so you can send email.

---

<div class="post-metadata">

### Author: ![Ryan\_N](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryan_n/32/200907_2.png) [@Ryan\_N](https://meta.discourse.org/u/Ryan_N)
#### Post date: [25 november 2020 om 02:54 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/4 "2020-11-25T02:54:55Z")

</div>

@tobiaseigen Getting closer! Made the change by dropping the incoming mail subdomain from the endpoint. Saved, then re-started the mail receiver (because I know not what I do!). Tested. No-luck. Then did a full rebuild of the app. Then made two new accounts using separate email addresses. I then used the admin account to PM one of these. That generated an email as expected. I then replied through email to the PM. Here’s the result in the mail log:

`<22>Nov 25 02:38:20 postfix/pipe[89]: AB09913F5CB: to=<replies+da32f82583043bb63fee8be53f9bd3fd@inbound.[mydomain].org>, relay=discourse, delay=0.35, delays=0.19/0/0/0.15, dsn=4.3.0, status=deferred (temporary failure)`

Indeed we’re getting closer! Not sure what the temporary failure is all about? It’s been 13 minutes, still not delivering into Discourse. Strange.

I should note, I made the “inbound” subdomain because I want an admin@[mydomain].org email address to be handled by a different mailhost.

---

<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: [25 november 2020 om 06:14 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/5 "2020-11-25T06:14:14Z")

</div>

I’m having a little trouble understanding your use of domain names. On my site the DISCOURSE\_MAIL\_ENDPOINT and MX record for inbound email is the same domain, pointing to the Discourse server, as explained in the OP in [Configure direct-delivery incoming email for self-hosted sites with Mail-Receiver](https://meta.discourse.org/t/straightforward-direct-delivery-incoming-mail/49487). You seem to be trying to use different domains.

Generally you want to use e.g. `forum.mydomain.org` type subdomain for your Discourse, to separate your forum from your main website and email on `mydomain.org`.

---

<div class="post-metadata">

### Author: ![Ryan\_N](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryan_n/32/200907_2.png) [@Ryan\_N](https://meta.discourse.org/u/Ryan_N)
#### Post date: [25 november 2020 om 19:33 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/6 "2020-11-25T19:33:53Z")

</div>

> [@tobiaseigen](#):
>
> I’m having a little trouble understanding your use of domain names.

Happy to clarify 🙂 and will pretend my domain is `thesite.org` for simplicity. What I do see, is a SSL issue in the mail-receiver logs:  
`<19>Nov 25 19:11:29 receive-mail[160]: Failed to POST the e-mail to https://inbound.thesite.org/admin/email/handle_mail: hostname "inbound.thesite.org" does not match the server certificate (OpenSSL::SSL::SSLError)`

To answer your question though, I had two goals which I presume are extremely common:

1. `admin@thesite.org` becomes an address for users to contact the admin
2. `thesite.org` launches the forum (no subdomain)

Presently my namecheap DNS settings look like this (TTL = Auto and Priority = 10):

```
1 A Record @ (IP address)     
2 A Record inbound. (IP Address)    
3 CNAME email.mg. mailgun.org.   
4 CNAME inbound. thesite.org.   
5 CNAME www. thesite.org.    
6 TXT @ forward-email=(stuff)
7 TXT mg v=spf1 include:mailgun.org ~all
8 TXT smtp._domainkey.mg. k=rsa; p=(stuff)
9 MX @ mx1.forwardemail.net.  
10 MX @ mx2.forwardemail.net.
11 MX inbound. thesite.org.
12 MX mg. mxa.mailgun.org.
13 MX mg. mxb.mailgun.org.

```

My **containers/mail-receiver.yml** settings are::  
`MAIL_DOMAIN: inbound.thesite.org`  
`DISCOURSE_MAIL_ENDPOINT: 'https://thesite.org/admin/email/handle_mail'`  
`DISCOURSE_API_KEY: (stuff)`  
`DISCOURSE_API_USERNAME: system` ← same as API key  
\* _note_—\> I left the LetsEncrypt lines as-is (did not remove the “#”)

Other settings:

- changed via command line the hostname to `inbound.thesite.org`
- contact email = `admin@thesite.org`
- notification email = `noreply@mg.thesite.org`
- reply-by email1 = `replies+%{reply_key}@inbound.thesite.org`
- reply-by email2 = `%{reply_key}@inbound.thesite.org`
- find related post with key = ON
- manual polling = ON
- mailgun API key = ENTERED …_but_ this might be a problem because its from a previous install attempt
- Settings \> Emails \> Settings: Address = `smtp.mailgun.org`
- Settings \> Emails \> Settings: Port = 2525
- Settings \> Emails \> Settings: user\_name = `postmaster@mg.thesite.org`

Any thoughts on where I go from here? …and a huge THANK YOU in advance! Pinging also @pfaffman as he has also so kindly been a resource helping me with past struggles involving setup. Your “Straightforward” guide was extremely useful too. Cheers!

---

<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: [25 november 2020 om 19:45 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/7 "2020-11-25T19:45:26Z")

</div>

> [@Ryan\_N](#):
>
> \<19\>Nov 25 19:11:29 receive-mail[160]: Failed to POST the e-mail to [https://inbound.thesite.org/admin/email/handle\_mail:](https://inbound.thesite.org/admin/email/handle_mail:) hostname “[inbound.thesite.org](http://inbound.thesite.org)” does not match the server certificate (OpenSSL::SSL::SSLError)

Did you rebuild both the mail and app containers? I think the easy solution is to remove the stuff that tries to give the mail receiver a certificate. Does the cert work for the site?

If the Discourse site is not at `inbound.thesite.org` that’s the problem. The idea is that the hostname of both the Discourse site and the mail receiver will be the same. You’ll need to find [Setting up Let’s Encrypt with Multiple Domains](https://meta.discourse.org/t/setting-up-let-s-encrypt-with-multiple-domains/56685) to fix that.

This is rather beyond the intended scope of the mail-receiver howto. If this isn’t enough to get you on track and you have a budget, feel free to contact me.

---

<div class="post-metadata">

### Author: ![Ryan\_N](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryan_n/32/200907_2.png) [@Ryan\_N](https://meta.discourse.org/u/Ryan_N)
#### Post date: [25 november 2020 om 20:18 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/8 "2020-11-25T20:18:44Z")

</div>

So the question becomes; can **both** goals I defined above be had (they seem absurdly common)? Is the only workaround to redirect, in the dns settings, visitors who type `www.thesite.org` and/or `thesite.org` to `subdomain.thesite.org`? If this is true, then I will have to just live with changing the forward facing email address to something ugly like `admin@subdomain.thesite.org`.

I can live with changing the admin email address if I absolutely have to. It seems like we’re overlooking something obvious but maybe I’m out in left field (I probably am!).

---

<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: [25 november 2020 om 20:21 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/9 "2020-11-25T20:21:16Z")

</div>

If what you want is for the mail receiver to receive mail at a domain different from your discourse domain, I think you can. The easiest thing is to not use the let’s encrypt cert in the mail receiver.

---

<div class="post-metadata">

### Author: ![Ryan\_N](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryan_n/32/200907_2.png) [@Ryan\_N](https://meta.discourse.org/u/Ryan_N)
#### Post date: [25 november 2020 om 20:55 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/10 "2020-11-25T20:55:03Z")

</div>

@pfaffman you’re a genius! It worked!! 👏 👏 👏 Following _Setting up Let’s Encrypt with Multiple Domains_, the re-building Discourse followed by rebuilding mail-receiver (one of the two probably wasn’t necessary), did the trick. Voila!

Later this evening, I’d like to copy/paste the “Straightforward direct-delivery incoming mail” OP into a Google Doc and offer my suggested edits to that. At no fault to any of you, there are parts of the OP that are not intuitive to someone like me who doesn’t know or understand command-line stuff. I think the two goals I defined above are very common for many installations, and now I know the end-goal can be accomplished.

I have other suggestions for the entire setup tutorial. Have a running list of suggested edits to make the process as simple as possible.

Thanks so much for helping me along here! Super appreciated!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [25 december 2020 om 20:55 UTC](https://meta.discourse.org/t/able-to-receive-e-mail-in-mail-receiver-but-not-in-discourse/171235/11 "2020-12-25T20:55:09Z")

</div>

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