Help using Gmail with Docker Ghost

I’m trying to setup gmail for transactional emails on my blog but I keep hitting errors. I’m using Ghost 5.55.0 and MySQL 8 running in docker 24.0.6 on Ubuntu 22.04.

My docker configuration is here: Ghost Docker compose - Pastebin.com

When I try to sign up for a user account, I get an error in the interface saying “Failed to send magic link email” and the logs show the following error:

[2023-09-22 12:58:03] ERROR "POST /members/api/send-magic-link/" 500 8469ms

Failed to send email. Reason: Sending failed.

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

Error ID:
    aad3c760-5947-11ee-a9af-03e019494d5f

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

Error: Sending failed
    at createMailError (/var/lib/ghost/versions/5.55.0/core/server/services/mail/GhostMailer.js:68:12)
    at DirectMailer.<anonymous> (/var/lib/ghost/versions/5.55.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:157:41)
    at DirectMailer.<anonymous> (/var/lib/ghost/versions/5.55.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:228:30)
    at /var/lib/ghost/versions/5.55.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:350:28
    at callback (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:374:14)
    at SMTPConnection.<anonymous> (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:385:20)
    at SMTPConnection._actionMAIL (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:1252:16)
    at SMTPConnection.<anonymous> (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:759:14)
    at SMTPConnection._processResponse (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:669:16)
    at SMTPConnection._onData (/var/lib/ghost/versions/5.55.0/node_modules/smtp-connection/lib/smtp-connection.js:493:10)
    at TLSSocket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)

[2023-09-22 13:07:39] INFO Worker for job "mentions-email-report" online
[2023-09-22 13:07:39] INFO Worker for job mentions-email-report sent a message: done

I’m sure there’s a really simple error in my configuration, but I can’t for the life of me find what it is!
type or paste code here

In your Docker Compose file, did you try setting the “secure” option for Gmail to true?

Also check that:

  • You are running your Docker container such that it has access to the host network or whatever else it needs to access the outside world.
  • From the host, test you can make the SMTP connection directly to Gmail outside of Ghost. That will isolate whether the issue is with your networking or credentials or whether the issue is with your Ghost or Docker configuration.

See for example: Connecting to smtp.gmail.com via command line - Stack Overflow

Also, check that your hoster isn’t blocking outgoing access to the SMTP port you are trying.

Thanks @markstos your advice was sound, and I was able to confirm that I could make SMTP connections from the host to gmail.

That got me looking for other sample docker-compose files that included gmail and I eventually found an article on Marius Hosting that had slightly different docker-compose settings - once the email lines in my own docker-compose were replaced, it worked straight away!

The new settings that allowed me to send emails via gmail are:

      mail__transport: SMTP
      mail__options__service: SMTP
      mail__from: Your-own-gmail-address
      mail__options__host: smtp.gmail.com
      mail__options__port: 587
      mail__options__auth__user: Your-own-gmail-address
      mail__options__auth__pass: Your-own-app-password
1 Like