title: Why am I getting time out errors when sending emails from Amazon ECS container?
body: <p>I have a Spring Boot API which has a service to send emails. This service works when I'm running the app locally or with a simple docker-compose inside an EC2 instance. However when I moved the app to Amazon ECS, it stopped working.</p>
  <p>The error:</p>
  <pre><code>org.springframework.mail.MailSendException: Mail server connection failed; nested exception is
  com.sun.mail.util.MailConnectException: Couldn't connect to host, port: email-smtp.us-east-
  1.amazonaws.com, 587; timeout -1;
  </code></pre>
  <p>My application.yml (mail section):</p>
  <pre><code>spring:
      mail:
      host: ${MAIL_HOST}
      port: ${MAIL_PORT:587}
      username: ${MAIL_USER}
      password: ${MAIL_PASSWORD}
      properties:
        mail:
          smtp:
            auth: true
            starttls.enable: true
  
  </code></pre>
  <p>I've already tried to open the tcp port 587 in my security group, but it didn't work too.</p>
  <p><strong>More info about ECS:</strong><br>
  I'm using ECS with EC2 launch type and an Application Load Balancer sitting in front of it.</p>