Search code examples
amazon-ecsaws-fargatepostfix-mta

Postfix running as a task in ECS not working


I have a postfix container running in ECS, which I've configured to use port 2525 as I've read port 25 could be blocked.

When I try and establish a connection to it (directly to the tasks private IP taken from the networking tab of the task in the AWS console) from a node app using nodemailer I'm getting an error Greeting never received. Nothing is logged in the postfix container.

However if I curl the IP and port 2525, postfix logs warning: non-SMTP command from localhost[127.0.0.1]: GET / HTTP/1.1. This warning makes sense, and proves that the port is open and receiving calls.

If I use telnet it connects, but then if I issue the standard SMTP HELO command I get:

HELO [email protected]
HTTP/1.1 400 Bad Request
content-length: 11
content-type: text/plain
date: Wed, 08 May 2024 16:40:25 GMT
server: envoy
connection: close

What could be going on? It's like ECS is forcing traffic to be HTTP when it should be TCP? The exact same container and configuration running locally works fine and the HELO returns the expected response.

The container is running in fargate


Solution

  • The issue was caused by the appProtocol setting in the portMappings block in the task definition:

    portMappings = [
            {
              "name" : "postfix",
              "containerPort" : 2525,
              "hostPort" : 2525,
              "protocol" : "tcp",
              "appProtocol" : "http"
            }
          ]
    

    Removing the appProtocol allowed the SMTP connection to be made.