Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable reverse DNS lookup? #230

Closed
atesca09 opened this issue Jan 3, 2024 · 6 comments
Closed

How to disable reverse DNS lookup? #230

atesca09 opened this issue Jan 3, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@atesca09
Copy link

atesca09 commented Jan 3, 2024

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: [email protected]
To: [email protected]
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 [email protected] --mail-rcpt [email protected] --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

@axllent
Copy link
Owner

axllent commented 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.

@atesca09
Copy link
Author

atesca09 commented 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

@axllent
Copy link
Owner

axllent commented 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)?

@atesca09
Copy link
Author

atesca09 commented 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

@axllent
Copy link
Owner

axllent commented 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 [email protected] --mail-rcpt [email protected] --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.

@atesca09
Copy link
Author

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

@axllent axllent closed this as completed Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants