Ghost Email Setup with Nginx Reverse Proxy

Trying to setup ghost with ghost community docker image.

The problem I face is that the mail setup is working on my locally run docker-compose, but when run on the server with docker-compose and nginx reverse proxy the request times out.

This is my mail configuration.

...
    "mail": {
        "service": "Gmail",
        "transport": "SMTP",
        "options": {
            "host": "smtp.gmail.com",
            "port": 465,
            "secureConnection": true,
            "auth": {
                "user": "XXXXXXXX@gmail.com",
                "pass": "XXXXXXXXX"
            }
        }
    },
...

I have been trying for the entire day to make sense of this and making no progress. I also tried Mailgun to set it up.

If anyone here has any experience of setting up ghost with nginx-proxy and letsencrypt in docker-compose and getting invitation email to work I will appreciate any pointer you can give me.

Ghose Version 3.15