Mail not working in Docker

  • What’s your URL? Docker network only
  • What version of Ghost are you using? 5.129.0

And

  • How was Ghost installed and configured? Docker, configured with an env file
  • What Node version, database, OS & browser are you using? node v20.19.3, MySQL v8.0, Ubuntu Linux
  • What errors or information do you see in the console? ESOCKET
  • What steps could someone else take to reproduce the issue you’re having? Similar environment try to sign in with 2FA enabled

Hi,

I have set the following environment variables:

mail__transport=SMTP
mail__options__host=172.17.0.1
mail__options__port=25
mail__options__secure=false

I have a mail server on 172.17.0.1 and I can connect to it and send mail by exec’ing into to the docker container and using netcat. I tried enabling DEBUG=* and it didn’t even mention anything about mail but I can’t send 2FA emails from within ghost, it says there was an error and to check the logs, which say ESOCKET but I don’t understand why the environment variables seem correct.

I also tried editing the configuration files inside the container and adding mail rules to them then restarting the container but this doesn’t work either.

My only option is to disable 2FA. I’d like to keep it though. Any advice?

Can you post the full error message, please?

What do the mailserver’s logs show, if anything?

Hi, the mail logs were revealing:

2025-07-03T22:58:40.015329+01:00 blog postfix/smtpd[102835]: connect from unknown[172.18.0.3]
2025-07-03T22:58:40.024169+01:00 blog postfix/smtpd[102835]: SSL_accept error from unknown[172.18.0.3]: lost connection
2025-07-03T22:58:40.024644+01:00 blog postfix/smtpd[102835]: lost connection after STARTTLS from unknown[172.18.0.3]
2025-07-03T22:58:40.024771+01:00 blog postfix/smtpd[102835]: disconnect from unknown[172.18.0.3] ehlo=1 starttls=0/1 commands=1/2

As for errors from ghost:

[2025-07-03 21:58:40] ERROR "POST /ghost/api/admin/session" 500 339ms

Failed to send email. Please check your site configuration and try again.

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."

Error ID:
    e0caf890-5858-11f0-82ee-a709bc14eca4

Error Code:
    ESOCKET

----------------------------------------

EmailError: Failed to send email. Please check your site configuration and try again.
    at Object.sendAuthCodeToUser (/var/lib/ghost/versions/5.129.0/core/server/services/auth/session/session-service.js:284:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.createSession (/var/lib/ghost/versions/5.129.0/core/server/services/auth/session/middleware.js:16:17)

So I poked around in the code a bit and removed the “friendly” error and it’s failing because postfix has a self-signed certificate. Why that’s a problem for it I don’t know but I can probably go from here and patch out that code.

Ahha. Ghost is using nodemailer under the hood. You might find this config page useful. SMTP transport | Nodemailer . You can probably pass in tls__rejectUnauthorized: false (check doc for exact name) to stop that, rather than maintaining a patched-out version. :)

1 Like

For anyone else experiencing this issue, the option is:

mail__options__tls__rejectUnauthorized=false

I now have a different error to solve, but it looks like a postfix issue so I will leave you for now, but thanks for the help!

1 Like