Not Able To Send Email using Nodemailer within Docker container due to EAI_AGAIN

I’ve setup Nodemailer in a docker container, but I haven’t been able to get emails to be sent. I ran the same code outside of docker to test whether it worked and it sends emails. So it has to be something to do with my docker container setup. The docker-compose and docker-file I’m using for development are not fancy, just the essentials, and I’m using the docker-toolbox since I don’t have Windows 10 pro.

I found similar questions like Nodemailer not sending mails after deploying it on docker container that is over a year old and contains no example code or answers. Also, found, and tried changing the port to 465 with TLS on and off, but still doesn’t send mail.


An EAI_AGAIN error is thrown, which I looked up and is a DNS lookup timeout issue so could be a network connectivity error or proxy related error, but I’m not a docker (or Devops) guru so I’m having issues figuring out how to resolve it. Can anyone explain how to get Nodemailer to work in a Docker container?

Error: getaddrinfo EAI_AGAIN
    at Object._errnoException (util.js:1021:11)
    at errnoException (dns.js:58:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:95:26)
    code: 'ECONNECTION',
    errno: 'EAI_AGAIN',
    syscall: 'getaddrinfo',
    hostname: '',
    host: '',
    port: 2525,
    command: 'CONN'

Docker Compose

    container_name: server
      context: .
      dockerfile: .docker/node.${APP_ENV}.dockerfile
      - "3000:3000"
    working_dir: ${NODE_WORKING_DIR}
      - ./.docker/env/node.${APP_ENV}.env
      - db
      - app-network

    // ... for brevity removed mysql, adminer, and network services

Docker File

# Pull in image
FROM node:latest

# Expose the default Express port

# Main entry point
ENTRYPOINT ["npm", "run", "start"]