SMTP relay to localhost is blocked

Issue Description

I want to send emails through a relay host. I’m running stalwart as a Docker container under Hashicorp Nomad, and using the Consul service mesh for network connectivity. My policy is that no direct outbound connection is allowed from workloads, except using services exposed through a dedicated terminating gateway (a Consul component providing outbound connectivity to specified services with strict ACL).

The problem is : exposing the relay host through a Consul terminating gateway means it’ll be available to stalwart on 127.0.0.1.

Configuring a relay resolving to 127.0.0.1 doesn’t work : Stalwart send a failure notice with “connection to ‘127.0.0.1’ failed: host resolves loopback address”

Expected Behavior

Stalwart shouldn’t forbid 127.0.0.1 as a valid relay, there’re legitimate cases for this (like a tunnel to the real relay)

Actual Behavior

Email is rejected with “connection to ‘127.0.0.1’ failed: host resolves loopback address”

Reproduction Steps

  1. Configure a SMTP relay pointing at 127.0.0.1
  2. The service running on 127.0.0.1 dosn’t need to be the final relay, it can be any tunneling tool (in my case, an envoy listener acting as a TCP proxy to the real relay)
  3. Try to send an email

Stalwart Version

v0.16.x

Installation Method

Docker

Database Backend

PostgreSQL

Blob Storage

PostgreSQL

Search Engine

PostgreSQL

Directory Backend

OIDC

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on