Email not working after configuring Cloudflare CDN

Ghost 5.11.0.

"mail": {
    "transport": "Direct"
  },
[2022-08-26 17:32:52] ERROR

NAME: EmailError
MESSAGE: Failed to send email. Reason: Sending failed.

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error: Sending failed
    at createMailError (/var/www/ghost/versions/5.11.0/core/server/services/mail/GhostMailer.js:67:12)
    at DirectMailer.<anonymous> (/var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:157:41)
    at DirectMailer.<anonymous> (/var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:201:22)
    at QueryReqWrap.callback (/var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:448:44)
    at QueryReqWrap.onresolve [as oncomplete] (node:dns:213:10)

[2022-08-26 17:32:52] INFO "POST /members/api/send-magic-link/" 500 138ms

I have set up the Cloudflare default DKIM, DMARC, and SPF DNS configuration. Does anyone know what is the problem or where else to debug?

I didn’t even know Cloudflare did email - unless it was just DNS records or proxying existing ones, but either way - you are positive you configured more of the configurations and just didn’t post them? The error looks like it was not configured properly but since all I can see is the direct transport - I don’t know.

Was this previously working on your host? The message says the transactional email failed to send, so check the server logs, e.g., /var/log/mail.

It would be really helpful if you shared some useful information about the host OS and outgoing mail server / service.

Yep, I mean it’s just the DNS records. And the above config is a snipped one.

Yes, it was, it didn’t work after I finished the Cloudflare CDN configuration. There is no /var/log/mail file. On syslog it shows:

Aug 27 14:35:09 xxx node[750]: #033[33m"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."#033[39m
Aug 27 14:35:09 xxx node[750]: #033[1m#033[37mError ID:#033[39m#033[22m
Aug 27 14:35:09 xxx node[750]:     #033[90m11bea310-260d-11ed-8150-ebb4a179f22d#033[39m
Aug 27 14:35:09 xxx node[750]: #033[90m----------------------------------------#033[39m
Aug 27 14:35:09 xxx node[750]: #033[90mError: Sending failed
Aug 27 14:35:09 xxx node[750]:     at createMailError (/var/www/ghost/versions/5.11.0/core/server/services/mail/GhostMailer.js:67:12)
Aug 27 14:35:09 xxx node[750]:     at DirectMailer.<anonymous> (/var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:157:41)
Aug 27 14:35:09 xxx node[750]:     at DirectMailer.<anonymous> (/var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:228:30)
Aug 27 14:35:09 xxx node[750]:     at /var/www/ghost/versions/5.11.0/node_modules/nodemailer-direct-transport/lib/direct-transport.js:350:28
Aug 27 14:35:09 xxx node[750]:     at callback (/var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:374:14)
Aug 27 14:35:09 xxx node[750]:     at /var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:389:24
Aug 27 14:35:09 xxx node[750]:     at SMTPConnection._actionSMTPStream (/var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:1358:16)
Aug 27 14:35:09 xxx node[750]:     at SMTPConnection.<anonymous> (/var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:854:18)
Aug 27 14:35:09 xxx node[750]:     at SMTPConnection._processResponse (/var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:669:16)
Aug 27 14:35:09 xxx node[750]:     at SMTPConnection._onData (/var/www/ghost/versions/5.11.0/node_modules/smtp-connection/lib/smtp-connection.js:493:10)
Aug 27 14:35:09 xxx node[750]:     at TLSSocket.emit (node:events:527:28)
Aug 27 14:35:09 xxx node[750]:     at addChunk (node:internal/streams/readable:315:12)
Aug 27 14:35:09 xxx node[750]:     at readableAddChunk (node:internal/streams/readable:289:9)
Aug 27 14:35:09 xxx node[750]:     at TLSSocket.Readable.push (node:internal/streams/readable:228:10)
Aug 27 14:35:09 xxx node[750]:     at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)#033[39m
Aug 27 14:35:09 xxx node[750]: #033[39m
Aug 27 14:35:09 xxx node[750]: [2022-08-27 13:35:09] #033[36mINFO#033[39m "POST /members/api/send-magic-link/" #033[31m500#033[39m 664ms

Seems there is something to do with TLS?
I do use ghost-cli SSL set-up. The CF SSL/TLS setting is Full and the Universal SSL is activated.

OS: Ubuntu 20.04.4 LTS, and I didn’t use any outgoing mail server/service.

DNS Record:

If you’re using Ubuntu 20.04, the log should be /var/log/mail.log. For direct mail to work you need Sendmail (Postfix). This receives mail from Nodemail, looks up the MX records of the recipient, and transfers the email.

So what MTA did you install? And, how was Ghost (Nodemail) setup before these changes?

The DNS records you set up are usually associated with mail exchange, yet you haven’t setup any MX records.

The connection is proxied. I feel like I had the same problem couple of months back. Try turning off Proxy and use ‘DNS only’ in your Cloudflare DNS settings.

@mjw, the log does not exist. And I have no idea about the other configuration. I just realized that the time it’s working is when I use ghost as headless CMS.

@Lakshmi_Narasimman_V I have thought so it may be the culprit. Tried it out, and it’s no avail. The error log is just the same as the syslog one.

Anyway, thanks for the responses guys. Guess I’ll go the easy way using Mailgun.