[GH-ISSUE #230] How to disable reverse DNS lookup? #148

Closed
opened 2026-03-15 12:52:09 +03:00 by kerem · 6 comments
Owner

Originally created by @Atesca on GitHub (Jan 3, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/230

Mailpit uses smtpd as smtp server

smtpd tries to do a reverse DNS lookup of the IP sending the mail, see https://github.com/mhale/smtpd/blob/cfd012220c479797ab15cee042831c95ea95dd1e/smtpd.go#L244

docker compose generates a domain name based on <contianer_name>-<container_id>.<network_name>

if I run the Mailpit as part of a docker compose project the generated name might get too long and the reverse DNS lookup return bad rdata

dockerd[1528]: level=error msg="[resolver] failed to write response" error="dns: bad rdata"

with that bad rdata the lookup times out after 10 seconds and the sender is resolved as unknown

But the 10 second timeout is too long for the Symfony 4.4 Mailer which uses a timeout of 5 seconds, see https://github.com/symfony/mailer/blob/554b8c0dc2db9d74e760fd6b726f527364f03302/Transport/Smtp/Stream/SocketStream.php#L29

Even with newer versions of Symfony, waiting 10 seconds for the timeout to occur seems wrong

Steps to reproduce:

Create a directory really-long-project-name-for-testing-dns-rdata

add a docker-compose.yaml with:

version: '3.9'

services:
    mailpit:
      image: axllent/mailpit
      ports:
        - '8025:8025'

    curl:
      image: curlimages/curl
      volumes:
        - ./email.txt:/email.txt:ro
      depends_on:
        - mailpit

add a demo email.txt

From: sender@example.com
To: recipient@example.com
Subject: Email Subject

This is the body of the email.
It can contain multiple lines of text.

send the email with docker compose run --rm curl smtp://mailpit:1025 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file /email.txt

It will send the email with an "unknown" as the hostname of the sending IP, but it'll take 10 seconds which is too long to send emails from a Symfony 4.4 project

Originally created by @Atesca on GitHub (Jan 3, 2024). Original GitHub issue: https://github.com/axllent/mailpit/issues/230 Mailpit uses smtpd as smtp server smtpd tries to do a reverse DNS lookup of the IP sending the mail, see <https://github.com/mhale/smtpd/blob/cfd012220c479797ab15cee042831c95ea95dd1e/smtpd.go#L244> docker compose generates a domain name based on <contianer_name>-<container_id>.<network_name> if I run the Mailpit as part of a docker compose project the generated name might get too long and the reverse DNS lookup return bad rdata `dockerd[1528]: level=error msg="[resolver] failed to write response" error="dns: bad rdata"` with that bad rdata the lookup times out after 10 seconds and the sender is resolved as `unknown` But the 10 second timeout is too long for the Symfony 4.4 Mailer which uses a timeout of 5 seconds, see <https://github.com/symfony/mailer/blob/554b8c0dc2db9d74e760fd6b726f527364f03302/Transport/Smtp/Stream/SocketStream.php#L29> Even with newer versions of Symfony, waiting 10 seconds for the timeout to occur seems wrong Steps to reproduce: Create a directory `really-long-project-name-for-testing-dns-rdata` add a `docker-compose.yaml` with: ``` version: '3.9' services: mailpit: image: axllent/mailpit ports: - '8025:8025' curl: image: curlimages/curl volumes: - ./email.txt:/email.txt:ro depends_on: - mailpit ``` add a demo `email.txt` ``` From: sender@example.com To: recipient@example.com Subject: Email Subject This is the body of the email. It can contain multiple lines of text. ``` send the email with `docker compose run --rm curl smtp://mailpit:1025 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file /email.txt` It will send the email with an "unknown" as the hostname of the sending IP, but it'll take 10 seconds which is too long to send emails from a Symfony 4.4 project
kerem 2026-03-15 12:52:09 +03:00
Author
Owner

@axllent commented on GitHub (Jan 3, 2024):

@atesca09 Yes I can confirm this problem. There are two issues here:

  1. You are using an invalid (auto-generated) hostname for your docker environment which is longer than RFC1034 allows (max 63 characters). The solution (work-around) for you is to specify a --name <shorter-name> to your docker compose command and provide a valid hostname. There is an open issue for Docker relating to this.
  2. As you've discovered, this DNS 10s timeout in Mailpit is originating from the mhale/smtpd package, not Mailpit itself. The 10s timeout is however a hardcoded DNS lookup timeout in Go itself, so that timeout can't be changed in smtpd. Please refer to the open issue on smtpd where there is a request to optionally allow disabling the DNS lookup entirely (which I could then make configurable with a flag in Mailpit). Whilst this does not change the Docker bug (names longer than 63 chars), there are several other reasons one may want to disable DNS lookups in smtpd. Please feel free to add to that smtpd issue so the author understands the need and can then maybe implement the option to disable it sooner.

In the meantime there is nothing I can do here unfortunately.

<!-- gh-comment-id:1875979969 --> @axllent commented on GitHub (Jan 3, 2024): @atesca09 Yes I can confirm this problem. There are two issues here: 1. You are using an invalid (auto-generated) hostname for your docker environment which is longer than RFC1034 allows (max 63 characters). The solution (work-around) for you is to specify a `--name <shorter-name>` to your docker compose command and provide a valid hostname. There is an [open issue](https://github.com/moby/moby/issues/46928) for Docker relating to this. 2. As you've discovered, this DNS 10s timeout in Mailpit is originating from the `mhale/smtpd` package, not Mailpit itself. The 10s timeout is however a hardcoded DNS lookup timeout in Go itself, so that timeout can't be changed in smtpd. Please refer to the [open issue](https://github.com/mhale/smtpd/issues/40) on smtpd where there is a request to optionally allow **disabling** the DNS lookup entirely (which I could then make configurable with a flag in Mailpit). Whilst this does not change the Docker bug (names longer than 63 chars), there are several other reasons one _may_ want to disable DNS lookups in smtpd. Please feel free to add to that smtpd issue so the author understands the need and can then maybe implement the option to disable it sooner. In the meantime there is nothing I can do here unfortunately.
Author
Owner

@Atesca commented on GitHub (Jan 4, 2024):

@axllent yeah I thought so, I was just checking in, in case I missed something.

Unfortunately the workaround specifying a shorter name isn't an option for me in the current setup.

I guess we'll have to wait for smtpd to provide the option to skip the reverse DNS lookup

<!-- gh-comment-id:1877325484 --> @Atesca commented on GitHub (Jan 4, 2024): @axllent yeah I thought so, I was just checking in, in case I missed something. Unfortunately the workaround specifying a shorter name isn't an option for me in the current setup. I guess we'll have to wait for smtpd to provide the option to skip the reverse DNS lookup
Author
Owner

@axllent commented on GitHub (Jan 4, 2024):

@atesca09 I will probably submit a pull request to smtpd later today if get around to it. Out of curiosity, are you using Gitlab CI (in relation to it not being an option for you)?

<!-- gh-comment-id:1877713135 --> @axllent commented on GitHub (Jan 4, 2024): @atesca09 I will probably submit a pull request to smtpd later today if get around to it. Out of curiosity, are you using Gitlab CI (in relation to it not being an option for you)?
Author
Owner

@Atesca commented on GitHub (Jan 5, 2024):

@axllent No the issue for my use-case isn't in GitLab. Besides the workaround with emptying /etc/resolv.conf is unacceptable for the use-case. It is more a problem with the amount of projects that are affected (~100+) and the amount of changes that have to be made just to replace the old mailhog with mailpit

<!-- gh-comment-id:1879141075 --> @Atesca commented on GitHub (Jan 5, 2024): @axllent No the issue for my use-case isn't in GitLab. Besides the workaround with emptying /etc/resolv.conf is unacceptable for the use-case. It is more a problem with the amount of projects that are affected (~100+) and the amount of changes that have to be made just to replace the old mailhog with mailpit
Author
Owner

@axllent commented on GitHub (Jan 21, 2024):

@atesca09 This new feature has been released in v1.13.0 and should solve your issue completely. Starting Mailpit with either the --smtp-disable-rdns flag or setting MP_SMTP_DISABLE_RDNS=true in your environment (Docker) disables the reverse DNS entirely. Obviously you need to pull the latest axllent/mailpit image first :)

version: '3.9'

services:
  mailpit:
    image: axllent/mailpit
    environment:
      - MP_SMTP_DISABLE_RDNS=true
    ports:
      - '8025:8025'

  curl:
    image: curlimages/curl
    volumes:
      - ./email.txt:/email.txt:ro
    depends_on:
      - mailpit
time docker compose run --rm  curl smtp://mailpit:1025 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file /email.txt
[+] Creating 1/0
 ✔ Container really-long-project-name-for-testing-dns-rdata-mailpit-1  Running                                                                                                 0.0s 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   145    0     0  100   145      0  11276 --:--:-- --:--:-- --:--:-- 12083

real    0m0.878s
user    0m0.057s
sys     0m0.020s

Please confirm this resolves your issue? Thanks.

<!-- gh-comment-id:1902483148 --> @axllent commented on GitHub (Jan 21, 2024): @atesca09 This new feature has been released in v1.13.0 and should solve your issue completely. Starting Mailpit with either the `--smtp-disable-rdns` flag or setting `MP_SMTP_DISABLE_RDNS=true` in your environment (Docker) disables the reverse DNS entirely. Obviously you need to pull the latest `axllent/mailpit` image first :) ```yaml version: '3.9' services: mailpit: image: axllent/mailpit environment: - MP_SMTP_DISABLE_RDNS=true ports: - '8025:8025' curl: image: curlimages/curl volumes: - ./email.txt:/email.txt:ro depends_on: - mailpit ``` ```shell time docker compose run --rm curl smtp://mailpit:1025 --mail-from sender@example.com --mail-rcpt recipient@example.com --upload-file /email.txt [+] Creating 1/0 ✔ Container really-long-project-name-for-testing-dns-rdata-mailpit-1 Running 0.0s % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 145 0 0 100 145 0 11276 --:--:-- --:--:-- --:--:-- 12083 real 0m0.878s user 0m0.057s sys 0m0.020s ``` Please confirm this resolves your issue? Thanks.
Author
Owner

@Atesca commented on GitHub (Jan 21, 2024):

Confirmed, this works for me. Thanks a lot @axllent

<!-- gh-comment-id:1902566946 --> @Atesca commented on GitHub (Jan 21, 2024): Confirmed, this works for me. Thanks a lot @axllent
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#148
No description provided.