# Configure direct-delivery incoming email for self-hosted sites with Mail-Receiver

**URL:** https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487
**Category:** Self-Hosting
**Tags:** email, how-to, advanced-setup, mail-receiver
**Created:** [August 31, 2016, 10:58am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487 "2016-08-31T10:58:09Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [May 10, 2024, 4:27pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/490 "2024-05-10T16:27:30Z")

</div>

> [@Discourse](#):
>
> Now, go to your `/var/discourse` directory and create a new `mail-receiver.yml` container definition from the sample conveniently provided:

How is this done to create a new container definition in that directory!?

---

<div class="post-metadata">

### Author: ![Simon\_Manning](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon_manning/32/198596_2.png) [@Simon\_Manning](https://meta.discourse.org/u/Simon_Manning)
#### Post date: [May 10, 2024, 4:36pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/491 "2024-05-10T16:36:20Z")

</div>

By running the commands shown immediately following that text. Strictly speaking you aren’t creating the file in that directory but inside the `containers` subdirectory, same as `app.yml`.

---

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [May 10, 2024, 5:02pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/492 "2024-05-10T17:02:09Z")

</div>

Thanks, at first those didn’t seem to be working but now have gotten to the text editor with:

> [@Discourse](#):
>
> `nano containers/mail-receiver.yml`

There seems to be a problem with this, when running

./launcher logs mail-receiver

reports discourse\_base\_url=[https://discourse.example.com](https://discourse.example.com), instead of specified domain set in text editor.

Tried rebuilding/relaunching bootstrap of mail-receiver but hasn’t changed to correct domain.

---

<div class="post-metadata">

### Author: ![sober](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sober/32/344783_2.png) [@sober](https://meta.discourse.org/u/sober)
#### Post date: [May 18, 2024, 10:52am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/493 "2024-05-18T10:52:00Z")

</div>

Cause of error

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/8/6/186e5b3f301a4dac437b18b95e12d606db4aeac1.png)

---

<div class="post-metadata">

### Author: ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)
#### Post date: [May 19, 2024, 2:21am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/494 "2024-05-19T02:21:13Z")

</div>

I’m having a little trouble I could use some advice!

```plaintext
root@JEN /var/discourse # ./launcher start mail-receiver
x86_64 arch detected.

starting up existing container
+ /usr/bin/docker start mail-receiver
Error response from daemon: driver failed programming external connectivity on endpoint mail-receiver (721279d807e22a80580f2357fae40cc): Error starting userland proxy: listen tcp4 0.0.0.0:25: bind: address already in use
Error: failed to start containers: mail-receiver

```

then…

```plaintext
root@JEN /var/discourse # sudo lsof -i tcp:25
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
master 4400 root 13u IPv4 24419 0t0 TCP *:smtp (LISTEN)
master 4400 root 14u IPv6 24420 0t0 TCP *:smtp (LISTEN)

```

I also tried…

```plaintext
root@JEN /var/discourse # netstat -nlp | grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 4400/master
tcp6 0 0 :::25 :::* LISTEN 4400/master

```

and…

```plaintext
root@JEN /var/discourse # ps j 4400
   PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
      1 4400 4400 4400 ? -1 Ss 0 0:02 /usr/lib/postfix/sbin/master -w

```

I’m finding instructions online to stop the container and kill the process (process 4400?)

Is this safe, and will it correct the problem?

Do I need to (or should I, or should I not) change port 25 to a different port in the mail-receiver.yml file?

---

<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: [May 19, 2024, 5:09am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/495 "2024-05-19T05:09:10Z")

</div>

Maybe you installed postfix and need to remove it?

You can’t change the port. You need to stop whatever is using it. Just killing it won’t work because when your reboot it’ll be a race to see which process starts first.

---

<div class="post-metadata">

### Author: ![denvergeeks](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/denvergeeks/32/327671_2.png) [@denvergeeks](https://meta.discourse.org/u/denvergeeks)
#### Post date: [May 19, 2024, 7:10am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/496 "2024-05-19T07:10:50Z")

</div>

That’s what I was thinking too. I can’t imagine how it got on there, but I’ll try removing it. Otherwise I can just use gmail which seems to be working just fine.

---

<div class="post-metadata">

### Author: ![packman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/packman/32/289322_2.png) [@packman](https://meta.discourse.org/u/packman)
#### Post date: [June 8, 2024, 2:49pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/497 "2024-06-08T14:49:53Z")

</div>

I’ve just moved my forum to a new environment and as a result re-installed the mail-receiver. It looks like it’s a newer version than I previously had installed. The YML config has changed a little with DISCOURSE\_BASE\_URL replacing DISCOURSE\_MAIL\_ENDPOINT. The YML file contents reflect the change but the instructions at the top of this thread need updating.

Also when receiving an email that is bounced/rejected I’m getting the following errors…

```plaintext
Jun 08 11:50:42 mail-receiver postfix/smtp[117]: fatal: unknown service: smtp/tcp
Jun 08 11:50:42 mail-receiver postfix/smtp[118]: fatal: unknown service: smtp/tcp
Jun 08 11:50:43 mail-receiver postfix/qmgr[101]: warning: private/smtp socket: malformed response
Jun 08 11:50:43 mail-receiver postfix/qmgr[101]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Jun 08 11:50:43 mail-receiver postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 117 exit status 1
Jun 08 11:50:43 mail-receiver postfix/master[1]: warning: /usr/lib/postfix/sbin/smtp: bad command startup -- throttling
Jun 08 11:50:43 mail-receiver postfix/qmgr[101]: warning: private/smtp socket: malformed response
Jun 08 11:50:43 mail-receiver postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 118 exit status 1
Jun 08 11:50:43 mail-receiver postfix/qmgr[101]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description

```

Valid messages seem to be handled correctly. The previous version of mail-receiver didn’t give these errors as far as I could see from recent log files. I did a little research and came across - [smtp socket: malformed response on a FIPS 140-2 system](https://blog.badgerops.net/smtp-socket-malformed-response-on-a-fips140-2-sytstem/)

Adding the following to the mail-receiver.yml file seems to fix the problem for me:

```plaintext
  ## Fix smtp errors
  POSTCONF_smtp_tls_fingerprint_digest: sha256
  POSTCONF_smtpd_tls_fingerprint_digest: sha256

```

---

<div class="post-metadata">

### Author: ![kelv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kelv/32/524739_2.png) [@kelv](https://meta.discourse.org/u/kelv)
#### Post date: [June 29, 2024, 7:49am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/498 "2024-06-29T07:49:26Z")

</div>

Dropping a post here to note that we’ve added DMARC support to the mail-receiver via an image `discourse/mail-receiver:with-dmarc`. Please refer to [Configure direct-delivery incoming email for self-hosted sites with Mail-Receiver](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487#dmarc-support-experimental-9) in the OP for more details.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [July 5, 2024, 6:10am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/500 "2024-07-05T06:10:47Z")

</div>

2 posts were merged into an existing topic: [Mail-receiver relay access denied](https://meta.discourse.org/t/mail-receiver-relay-access-denied/145690/9)

---

<div class="post-metadata">

### Author: ![tkforbes](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tkforbes](https://meta.discourse.org/u/tkforbes)
#### Post date: [August 21, 2024, 7:37am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/501 "2024-08-21T07:37:39Z")

</div>

I wanted to add something for the Troubleshooting section.

Mail-Receiver (direct delivery) was working for several domains but not receiving messages from Gmail users. I couldn’t work out why. There was nothing in the logs except a connect/disconnect from Google. Everything looked good and the online tools confirmed DNS was fine.

Eventually I created an SMTP TLS report record in DNS e.g.

`_smtp._tls.discourse.mydomain.com TXT v=TLSRPTv1;rua=mailto:me@wherever.com`

A few hours later, Google (Gmail) sent a report showing that it had cached an mta-sts policy that did not reflect current MX records. I was concerned that Google was going to hang on to that cached policy for a week because it seemed to have ignored my updated \_mta-sts DNS record that should have caused a refresh.

And shortly after that, all my backed-up Gmail began to flow in to Discourse without me doing anything at all. The report helped me understand Google’s perspective on the problem and saved me from scratching my head when messages did begin to flow.

SMTP TLS reports are issued infrequently, so be patient.

---

<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: [August 21, 2024, 10:22pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/502 "2024-08-21T22:22:25Z")

</div>

Given that the guide says nothing about configuring MTA STS, wouldn’t adding diagnostic steps for that just confuse the 99.999%+ of users who don’t configure it?

---

<div class="post-metadata">

### Author: ![tkforbes](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tkforbes](https://meta.discourse.org/u/tkforbes)
#### Post date: [August 22, 2024, 12:32am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/503 "2024-08-22T00:32:36Z")

</div>

In my case, the addition of a single DNS record was enough to shine the light on my problem. Given that the guide already instructs the creation of DNS records for the installation of Mail-Receiver, suggesting an addition record in the Troubleshooting section as a last resort doesn’t seem like a stretch. However, I see that your post has two ‘likes’ and mine has none, so that might be the end of it.

---

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [August 22, 2024, 1:51pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/504 "2024-08-22T13:51:11Z")

</div>

> [@tkforbes](#):
>
> the addition of a single DNS record was enough to shine the light on my problem

That is good news, this seems like good info to add to guide especially since Gmail is a common sender.

---

<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: [August 23, 2024, 3:58am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/505 "2024-08-23T03:58:26Z")

</div>

> [@tkforbes](#):
>
> Given that the guide already instructs the creation of DNS records for the installation of Mail-Receiver, suggesting an addition record in the Troubleshooting section as a last resort doesn’t seem like a stretch.

The guide instructs on the creation of DNS records to make mail-receiver work, not to configure MTA STS. So a user following the guide will never have the problem you had. Hence there’s no need to complicate the guide with additional, unnecessary steps.

---

<div class="post-metadata">

### Author: ![Architect](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/architect/32/520575_2.png) [@Architect](https://meta.discourse.org/u/Architect)
#### Post date: [August 23, 2024, 6:07am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/506 "2024-08-23T06:07:17Z")

</div>

> [@mpalmer](#):
>
> to make mail-receiver work

In general is the mail-receiver able to process gmail sent mail to new topics?

> [@tkforbes](#):
>
> not receiving messages from Gmail users

This seems like a major problem, but not if the cause of this is an isolated incident.

---

<div class="post-metadata">

### Author: ![tkforbes](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tkforbes](https://meta.discourse.org/u/tkforbes)
#### Post date: [August 23, 2024, 10:45am UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/507 "2024-08-23T10:45:54Z")

</div>

I’ve come to the conclusion that Matt is right. My installation specifically had to cope with MTA-STS because its domain’s regular mail is handled by _Mail In a Box_ [https://mailinabox.email/](https://mailinabox.email/) which insists on a strict MTA-STS policy and Gmail enforces that policy. By default, the policy could conflict with configuration for Mail-Receiver. Most domains will not have a policy. If a domain does have a policy it will be visible at

`https://mydomain.com/.well-known/mta-sts.txt`

My working policy looks like this…

> version: STSv1  
> mode: none  
> mx: [mail.mydomain.com](http://mail.mydomain.com)  
> mx: [discourse.mydomain.com](http://discourse.mydomain.com)  
> max\_age: 86400

I am hoping to upgrade _"mode: none_" to _“mode: enforce”_ after a little more work.

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [August 29, 2024, 5:05pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/508 "2024-08-29T17:05:09Z")

</div>

Could someone please remind me – when we rebuild Discourse at the command line, does it automatically rebuild the mail-receiver container, or do we need to do that separately? Thanks.

---

<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: [August 29, 2024, 5:48pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/509 "2024-08-29T17:48:07Z")

</div>

> [@Jonathan5](#):
>
> does it automatically rebuild the mail-receiver container

It does not; it rebuilds just when you tell it to. You don’t need to rebuild the mail receiver often.

---

<div class="post-metadata">

### Author: ![Ashmerelda](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@Ashmerelda](https://meta.discourse.org/u/Ashmerelda)
#### Post date: [September 10, 2024, 1:03pm UTC](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487/510 "2024-09-10T13:03:07Z")

</div>

> [@jericson](#):
>
> I dunno if any of this will help others, but it would have helped me. 😉

It definitely helped me:)

[Previous page](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487.md?page=1)

[Next page](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487.md?page=3)
