mailpit icon indicating copy to clipboard operation
mailpit copied to clipboard

Discrepancy on bound addresses

Open jure965 opened this issue 3 years ago • 5 comments

Hey, great work and thank you for this excellent tool.

I've found a small discrepancy on what the program is reporting and what's actually happening, may be just cosmetic.

The log after starting Mailpit:

Nov 25 20:56:56 mailpit systemd[1]: Started mailpit.service - Mailpit dev mail server.
Nov 25 20:56:56 mailpit mailpit[953]: INFO[2023/11/25 20:56:56] [smtpd] starting on 0.0.0.0:1025
Nov 25 20:56:56 mailpit mailpit[953]: INFO[2023/11/25 20:56:56] [http] starting server on http://localhost:8025/

Gives the impression it started http server on 127.0.0.1 (a.k.a. localhost). In reality it's bound to all interfaces, as shown by the ss tool:

root@mailpit:/var/lib# ss -tunlp
Netid  State   Recv-Q   Send-Q     Local Address:Port     Peer Address:Port  Process
tcp    LISTEN  0        100            127.0.0.1:25            0.0.0.0:*      users:(("master",pid=280,fd=13))
tcp    LISTEN  0        128                    *:1025                *:*      users:(("mailpit",pid=915,fd=7))
tcp    LISTEN  0        4096                   *:22                  *:*      users:(("sshd",pid=127,fd=3),("systemd",pid=1,fd=52))
tcp    LISTEN  0        128                    *:8025                *:*      users:(("mailpit",pid=915,fd=8))
tcp    LISTEN  0        100                [::1]:25               [::]:*      users:(("master",pid=280,fd=14))

The systemd service unit file for the curious:

[Unit]
Description=Mailpit catchall mail server
Documentation=https://github.com/axllent/mailpit
After=network.target

[Service]
User=mailpit
Group=mailpit
ExecStart=/usr/local/bin/mailpit -d /var/lib/mailpit/mailpit.sqlite
PrivateTmp=true

[Install]
WantedBy=multi-user.target

jure965 avatar Nov 25 '23 21:11 jure965

Hi @jure965. Yes you are 100% correct, Mailpit does listen by default to [::]:8025 (HTTP) and [::]:1025 (SMTP), which means all interfaces for both ipv4 and ipv6 (if enabled). The issue is that this cannot be represented nicely in the logging output in a manner users actually understand (ie: would say something like [http] starting server on http://[::]:8025/), which I don't believe works in all browsers on all platforms if pasted into the browser. For this reason, the log output is currently artificially manipulated via these two functions to say [http] starting server on http://localhost:8025/.

In my attempt to not confuse users, I have obviously confused others such as yourself.

Maybe the log should say something like:

INFO[2023/11/26 13:02:54] [smtpd] starting on [::]:1025
INFO[2023/11/26 13:02:54] [http] starting on [::]:8025
INFO[2023/11/26 13:02:54] [http] accessible via http://localhost:8025/ 

I am open to your suggestions as how to better represent this in the Mailpit logs, preferably with a clickable link that can be used on all platforms.

axllent avatar Nov 26 '23 00:11 axllent

What you suggested is absolutely fine. Letting the user know where he can open the web UI in a separate log entry is good.

As for creating a clickable link, I'm sure there is a go library that can create platform/terminal specific hyperlinks. I found this one, which looks promising: https://github.com/savioxavier/termlink

jure965 avatar Nov 26 '23 08:11 jure965

Thanks for the feedback 👍 I will look into this as soon as I'm able to (I'm away for the next 5 days).

axllent avatar Nov 26 '23 18:11 axllent

This has been released in v1.10.2. Please confirm this works as you expected?

axllent avatar Dec 01 '23 02:12 axllent

Yes, I confirm this works as expected now, thanks!

jure965 avatar Dec 01 '23 20:12 jure965