Subscribe Failed to send magic link email Error

My site is up and running. Everything including sending newsletter emails and signing in works. The only issue I am having is when I try to put in another email address of mine to test if the subscribe option works on my site. Everytime I input an email into subscribe, an error comes up saying “Failed to send magic link email”. I checked Mailgun and my config production file and there is nothing wrong. I set it up correctly as suggested online. I am not sure how can I troubleshoot the error.

This is how my config file is set up:

"mail": {
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.mailgun.org",
      "port": 587,
      "secure": false,
      "auth": {
        "user": "mailgun username">
        "pass": "mailgun password">
      }
    }
  },

The error

Ghost-CLI version: 1.23.1
Ghost version: 5.25.2
Free Plan Mailgun
Mac Os Ventura 13.0.1
Hosted on Digital Ocean

I am not sure what other information is needed.

Your config has errors, and is missing a line.

I tried what was suggested but it does not seem to have worked and now I am getting another error when I try to input the same email to test out subscribe: “Too many different sign-in attempts try again in 15 minutes”. I will wait the 15 minutes and retry again then end up with the same exact error. I tried to use ghost doctor and ghost logs and I can’t seem to find what the issue is. I checked the logs in mailgun and it seems to be working completely fine. I also tried a different email address and still ended up with the same error.

Below is what I currently have.

"mail": {
    "from": "'Local & Foreign' <noreply@localandforeign.com>",
    "transport": "SMTP",
    "options": {
      "host": "smtp.mailgun.org",
      "port": 587,
      "service": "Mailgun",
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "mailgun email",
        "pass": "password"
      }
    }
  },

This isn’t an error message; Ghost blocks repeated login attempts. Furthermore, after changing the configuration file, you need to execute ghost restart.

You should also check that you haven’t blocked port 587 in your firewall. You can test using telnet server.domain.com 587.

With every change to the config file, I restarted ghost and tried again. I just checked to see if the port 587 is blocked in the firewall and this is what I got:

ghost-mgr@username:/var/www/ghost$  telnet server.domain.com 587
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

If this means that the port is blocked how would I be able to unblock it in the firewall?

Did you take server.domain.com literally? You need to substitute this with the actual mail server.

That was a mistake, I just checked the mail server correctly and got the following:

ghost-mgr@user:/var/www/ghost$  telnet smtp.mailgun.org 587
Trying 34.83.33.178...
Connected to smtp.mailgun.org.
Escape character is '^]'.
220 Mailgun Influx ready
Connection closed by foreign host.

Okay, so the port isn’t blocked.

I’d check your credentials; this is not the same as logging into Mailgun, and can be found under SMTP settings. Finally, make sure you have the correct server, e.g., smtp.eu.mailgun.org, smtp.mailgun.org, and test using command line, i.e., swaks.

I tried checking again, still the same issue. I am going to check with Digital Ocean and see if maybe the issue is from my droplet. I just read that with new accounts they tend to block SMTP with new accounts.

Thank you very much for your help!

1 Like

If this were the situation, you wouldn’t have successfully connected to their server on port 587.

Did you check your credentials? Note the password length, and email.

      "auth": {
        "user": "postmaster@mg.yourdomain",
        "pass": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx-xxxxxxxx"

Try this:

# Install Swaks
curl http://www.jetmore.org/john/code/swaks/files/swaks-20130209.0/swaks -o swaks
chmod +x swaks
# Install Perl
sudo apt --yes install perl
# Send a test message
./swaks --auth \
        --server smtp.mailgun.org \
        --au postmaster@mg.yourdomain \
        --ap xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx-xxxxxxxx \
        --to foo@bar.com \
        --h-Subject: "Hello" \
        --body 'Testing Mailgun'

The credentials are correct since I copied and pasted them into the config file.

After running the swaks code I got the following:

=== Trying smtp.mailgun.org:25...
*** Error connecting to smtp.mailgun.org:25:
***     IO::Socket::INET: connect: timeout

You should use port 587 as described earlier, so try this:

swaks --auth \
        --server smtp.mailgun.org:587 \
        -tls \
        --au postmaster@mg.yourdomain \
        --ap xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-xxxxxxxx-xxxxxxxx \
        --to foo@bar.com \
        --h-Subject: "Hello" \
        --body 'Testing Mailgun'

I just tried and got this:

=== Trying smtp.mailgun.org:587...
=== Connected to smtp.mailgun.org.
<-  220 Mailgun Influx ready
 -> EHLO ghostonubuntu2204-s-1vcpu-1gb-nyc1-01
<-  250-6b5c91d0d79d
<-  250-AUTH PLAIN LOGIN
<-  250-SIZE 52428800
<-  250-8BITMIME
<-  250-SMTPUTF8
<-  250-PIPELINING
<-  250 STARTTLS
 -> STARTTLS
<-  220 Go ahead
=== TLS started with cipher UNKNOWN(0x0304):TLS_AES_128_GCM_SHA256:128
=== TLS no local certificate set
=== TLS peer DN="/C=US/ST=Texas/L=San Antonio/O=MAILGUN TECHNOLOGIES, INC/CN=*.mailgun.org"
 ~> EHLO ghostonubuntu2204-s-1vcpu-1gb-nyc1-01
<~  250-6b5c91d0d79d
<~  250-AUTH PLAIN LOGIN
<~  250-SIZE 52428800
<~  250-8BITMIME
<~  250-SMTPUTF8
<~  250 PIPELINING
 ~> AUTH LOGIN
<~  334 VXNlcm5hbWU6
 ~> cG9zdG1hc3RlckBzYW5kYm94ODllNmIzMzRiZjgyNGMyZmI2M2NhN2FjYjdiODBlZDgubWFpbGd1bi5vcmc=
<~  334 UGFzc3dvcmQ6
 ~> ODE3NGVlOWJmMzVkY2YxOWU4NGJhMTE0ZDBmNjZmZjctNzc5ODU1NjAtOGE3OWVhNWI=
<~  235 Authentication successful
 ~> MAIL FROM:<ghost-mgr@ghostonubuntu2204-s-1vcpu-1gb-nyc1-01>
<~  250 Sender address accepted
 ~> RCPT TO:<foo@bar.com>
<~  250 Recipient address accepted
 ~> DATA
<~* 421 Domain sandbox1234.mailgun.org is not allowed to send: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
 ~> QUIT
<~  221 See you later. Yours truly, Mailgun
=== Connection closed with remote host.

This proves that Mailgun is working correctly with the supplied credentials … you should have replaced foo@bar.com with one of your personal emails, so you received the message.

The next step is to look at the logs. These are located in ./content/logs.

Not sure how would I get the logs from ./content/logs.

Go to the folder that Ghost is installed, e.g., /var/www/ghost, and then cd content/logs. You should be interested in the file ending error.log.

I managed to get into the error log and it gave the following output:
I inputed a part of it since it was a repetition of the same thing.

{"name":"Log","hostname":"ghostonubuntu2204-s-1vcpu-1gb-nyc1-01","pid":10372,"level":50,"err":{"id":"11cc2300-77cf-11ed-bd6c-1fb8
a9b4282d","domain":"https://localandforeign.com","code":"EENVELOPE","name":"EmailError","statusCode":500,"level":"normal","messag
e":"Failed to send email. Reason: Data command failed: 421 Domain sandbox.mailgun.org is not allowed to send: Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipient
s in Account Settings..","help":"\"Please see https://ghost.org/docs/config/#mail for instructions on configuring email.\"","stac
k":"Error: Data command failed: 421 Domain sandbox.mailgun.org is not allowed to send: Sandbox su
bdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.\
n    at createMailError (/var/www/ghost/versions/5.25.2/core/server/services/mail/GhostMailer.js:68:12)\n    at SMTPConnection._f
ormatError (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)\n    at SMTPConnection._a
ctionDATA (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:1656:34)\n    at SMTPConnection.<a
nonymous> (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:1628:26)\n    at SMTPConnection._p
rocessResponse (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:953:20)\n    at SMTPConnectio
n._onData (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:755:14)\n    at TLSSocket.SMTPConn
ection._onSocketData (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:193:44)\n    at TLSSock
et.emit (node:events:513:28)\n    at addChunk (node:internal/streams/readable:315:12)\n    at readableAddChunk (node:internal/str
eams/readable:289:9)\n    at TLSSocket.Readable.push (node:internal/streams/readable:228:10)\n    at TLSWrap.onStreamRead (node:i
nternal/stream_base_commons:190:23)","hideStack":false},"msg":"Failed to send email. Reason: Data command failed: 421 Domain sand
box.mailgun.org is not allowed to send: Sandbox subdomains are for test purposes only. Please add
your own domain or add the address to authorized recipients in Account Settings..","time":"2022-12-09T14:37:55.890Z","v":0}
{"name":"Log","hostname":"ghostonubuntu2204-s-1vcpu-1gb-nyc1-01","pid":20867,"level":50,"err":{"domain":"https://localandforeign.
com","code":"platform_api_key_expired","statusCode":401,"message":"Expired API Key provided: sk_live_****************************
*****************************************************************. 

Platform access may have been revoked.","stack":"Error: 
Expired API Key provided: sk_live_*********************************************************************************************. Platform access may have been revoked.\n    at res.toJSON.then.StripeAPIError.message (/var/www/ghost/versions/5.25.2/node_
modules/stripe/lib/StripeResource.js:214:23)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"},"msg":"
Expired API Key provided: sk_live_*********************************************************************************************. 



domain":"https://localandforeign.com","code":"ETIMEDOUT","name":"EmailError","statusCode":500,"l
evel":"normal","message":"Failed to send email. Reason: Greeting never received.","help":"\"Please see https://ghost.org/docs/config/#mail for instructions on configuring email.\"","stack":"Error: Greeting never received\n    at createMailError (/var/www/ghost/versions/5.25.2/core/server/services/mail/GhostMailer.js:68:12)\n    at SMTPConnection._formatError (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)\n    at SMTPConnection._onError (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:776:20)\n    at Timeout.<anonymous> (/var/www/ghost/versions/5.25.2/node_modules/nodemailer/lib/smtp-connection/index.js:710:22)\n    at listOnTimeout (node:internal/timers:559:17)\n    at processTimers (node:internal/timers:502:7)","hideStack":false},"msg":"Failed to send email. Reason: Greeting never received.","time":"2022-12-09T17:41:05.126Z","v":0}


You’re using the Mailgun sandbox, not the account setup for your domain. Have you set that up?

I tried to input my custom domain originally however since I am using the free account, it says I would have to update to paid plans. Over the weekend I will take a look at it and try to set it up properly again. I will let you know if that makes any difference, hopefully that will solve the issue. Thank you again for your help!

Search the forum regarding a free Mailgun account; you simply sign-up and then downgrade to the Flex tier.

I also suggest you read the guides on Ghost and Mailgun.