Can't set up smtp

I’m trying to set email sending on Ghost running inside docker (behind reverse proxy and cloudflare).

I’m using smtp2go as an smtp provider and I use credentials that work in other container (Bookstack). Here are the variables I pass to container:

mail__from: user@mydomain.com
mail__options__auth__user: username
mail__options__auth__pass: password
mail__options__host: mail.smtp2go.com
mail__options__port: 465
mail__options__secure: true
mail__options__service: smtp2go
mail__options__transport: SMTP

Here are the errors I see in the logs when attempting to send message:

[2024-08-09 16:44:06] ERROR "POST /ghost/api/admin/invites/" 500 2865ms

Error sending email: Failed to send email. Reason: Sending failed. Please check your email settings and resend the invitation.

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

Error ID:
    97b72c10-566e-11ef-9a09-ade95c20340c

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

Error: Sending failed
    at createMailError (/var/lib/ghost/versions/5.89.0/core/server/services/mail/GhostMailer.js:105:12)
    at DirectMailer.<anonymous> (/var/lib/ghost/versions/5.89.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:157:41)
    at DirectMailer.<anonymous> (/var/lib/ghost/versions/5.89.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:228:30)
    at /var/lib/ghost/versions/5.89.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:350:28
    at callback (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:374:14)
    at SMTPConnection.<anonymous> (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:385:20)
    at SMTPConnection._actionRCPT (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:1313:20)
    at SMTPConnection.<anonymous> (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:1265:26)
    at SMTPConnection._processResponse (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:669:16)
    at SMTPConnection._onData (/var/lib/ghost/versions/5.89.0/node_modules/smtp-connection/lib/smtp-connection.js:493:10)
    at TLSSocket.emit (node:events:517:28)
    at TLSSocket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:368:12)
    at readableAddChunk (node:internal/streams/readable:341:9)
    at Readable.push (node:internal/streams/readable:278:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

Has anyone managed to set up Ghost with smtp2go or any ideas what am I doing wrong?

The logs mentioned TLS, so I checked their support pages.

SMTP port: 2525 (or 80, 25, 8025 or 587 if that doesn’t work).

You need to set the port to 587 not 465 (which is depreciated anyway), and secure to false.

tried that and it didn’t work. Tried using the recommended Mailgun service and still can’t get it to work. I get:

[2024-08-18 20:51:37] ERROR "POST /ghost/api/admin/invites/" 500 150ms

Error sending email: Failed to send email. Reason: D8190C64F77F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:
. Please check your email settings and resend the invitation.

Environment section of my compose file looks like this:

    environment:
      url: https://domain.com
      mail__transport: SMTP
      mail__options__service: Mailgun
      mail__options__host: smtp.eu.mailgun.org
      mail__options__port: 587
      mail__options__auth__user: noreply-ghost@domain.com
      mail__options__auth__pass: somepass