[SOLVED]Failed to send email: Can not use IPv4 addresses with current network

Hi :slight_smile:

EDIT: If I restart ghost, the error disappears and works again… But after some time error comes again!

I have big problems getting loggin mail from my blog…

I get this error:

NAME: EmailError
CODE: EDNS
MESSAGE: Failed to send email. Reason: Can not use IPv4 addresses with current network.

Ghost-CLI version: 1.23.1
Ghost version: 5.17.1 (at /var/www/ghost)
ghost-mgr@skytower:/var/www/ghost$
Mysql 8
Node 16
Ubuntu 22.04

My blog: https://www.futurenode.dk

Ghost Log

+ sudo systemctl is-active ghost_www-futurenode-dk
[2022-10-03 17:18:39] INFO "GET /assets/dist/app.min.js?v=3d7fd312cf" 200 27ms
[2022-10-03 17:18:39] INFO "GET /public/cards.min.js?v=3d7fd312cf" 200 12ms
[2022-10-03 17:18:39] INFO "GET /public/comment-counts.min.js?v=3d7fd312cf" 200 11ms
[2022-10-03 17:18:40] INFO "GET /public/member-attribution.min.js?v=3d7fd312cf" 200 7ms
[2022-10-03 17:18:42] INFO "GET /members/api/member/" 204 3ms
[2022-10-03 17:18:42] INFO "GET /ghost/api/content/settings/?key=e7dfb95b57ff10d7ed79546499&limit=all" 200 36ms
[2022-10-03 17:18:42] INFO "GET /ghost/api/content/newsletters/?key=e7dfb95b57ff10d7ed79546499&limit=all" 200 33ms
[2022-10-03 17:18:42] INFO "POST /members/api/comments/counts/" 200 4ms
[2022-10-03 17:18:42] INFO "GET /ghost/api/content/tiers/?key=e7dfb95b57ff10d7ed79546499&limit=all&include=monthly_price,yearly_price,benefits" 200 48ms
[2022-10-03 17:19:08] INFO "POST /members/api/comments/counts/" 200 4ms
[2022-10-03 17:19:25] INFO "GET /public/member-attribution.min.js?v=3d7fd312cf" 200 5ms
[2022-10-03 17:19:25] INFO "GET /public/comment-counts.min.js?v=3d7fd312cf" 200 8ms
[2022-10-03 17:19:26] INFO "GET /assets/icons/menu-icons.svg?v=3d7fd312cf" 200 6ms
[2022-10-03 17:19:26] INFO "POST /members/api/comments/counts/" 200 5ms
[2022-10-03 17:20:14] INFO "GET /rss/" 200 93ms
[2022-10-03 17:20:48] INFO Worker for job "email-analytics-fetch-latest" online
[2022-10-03 17:20:48] INFO Worker for job email-analytics-fetch-latest sent a message: Fetched 1 events and aggregated stats for 1 emails in 187ms
[2022-10-03 17:20:48] INFO Worker for job email-analytics-fetch-latest sent a message: done
[2022-10-03 17:21:50] ERROR

NAME: EmailError
CODE: EDNS
MESSAGE: Failed to send email. Reason: Can not use IPv4 addresses with current network.

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error: Can not use IPv4 addresses with current network
    at createMailError (/var/www/ghost/versions/5.17.1/core/server/services/mail/GhostMailer.js:67:12)
    at GetAddrInfoReqWrap.callback (/var/www/ghost/versions/5.17.1/node_modules/nodemailer/lib/shared/index.js:217:35)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:132:8)

[2022-10-03 17:21:50] INFO "POST /members/api/send-magic-link/" 500 90ms
ghost-mgr@skytower:/var/www/ghost$

config.production.json

{
  "url": "https://www.futurenode.dk",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "*****",
      "password": "****",
      "database": "******"
    }
  },
  "mail": {
    "from": "'FutureNode.dk' <MYUSER@futurenode.dk>",
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.eu.mailgun.org",
      "port": 587,
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "MAILGUN-USER-LOGIN",
        "pass": "MAILGUN-USER-PASSWORD"
      }
    }
  },
  "logging": {
    "level": "info",
    "rotation": {
      "enabled": true,
      "period": "1d",
      "count": 10
    },
    "transports": [
      "file"
    ],
    "slowHelper": {
      "level": "warn",
      "threshold": 500
    }
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/www/ghost/content"
  }
}

I think this needs further investigation on your Ubuntu box. For whatever reason, IPV4 records aren’t resolved (I don’t think Mailgun’s SMTP servers have IPV6 addresses.)

Issue Summary

I can’t log in to my site (Front end) - I get this error: “Failed to log in, please try again”

If I restart ghost, the site works again for 1-2 days! Then the same error shows up again!

  • I have tried to use the default Casper theme, and it’s the same error!

  • I have also tried to reinstall my server (Ubuntu 22.04) and install ghost again! But still the same error!

  • Newsletter is working fine! (Mailgun)

I have tried both with mailgun and with another SMTP server! Both work fine, but after some days the error comes again!

I have tried this mailgun config:

  "mail": {
    "from": "'FutureNode.dk' <MYUSER@futurenode.dk>",
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.eu.mailgun.org",
      "port": 587,
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "MAILGUN-USER-LOGIN",
        "pass": "MAILGUN-USER-PASSWORD"
      }
    }
  },

I have also tried this custom SMTP Config

  "mail": {
    "from": "'FutureNode.dk' <MYUSER@futurenode.dk>",
    "transport": "SMTP",
    "options": {
      "service": "Simply",
      "host": "smtp.simply.com",
      "port": 587,
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "MYUSERNAME",
        "pass": "MYPASSWORD"
      }
    }
  },

Steps to Reproduce

I get this error when I try to log in to my site!

“Failed to log in, please try again”

If I restart ghost, its works again… But after 1-2 days it shows up again!

Here is my: config.production.json


{
  "url": "https://www.futurenode.dk",
  "server": {
    "port": 2368,
    "host": "127.0.0.1"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "*****",
      "password": "****",
      "database": "******"
    }
  },
  "mail": {
    "from": "'FutureNode.dk' <MYUSER@futurenode.dk>",
    "transport": "SMTP",
    "options": {
      "service": "Mailgun",
      "host": "smtp.eu.mailgun.org",
      "port": 587,
      "secure": false,
      "requireTLS": true,
      "auth": {
        "user": "MAILGUN-USER-LOGIN",
        "pass": "MAILGUN-USER-PASSWORD"
      }
    }
  },
  "logging": {
    "level": "info",
    "rotation": {
      "enabled": true,
      "period": "1d",
      "count": 10
    },
    "transports": [
      "file"
    ],
    "slowHelper": {
      "level": "warn",
      "threshold": 500
    }
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/www/ghost/content"
  }
}

Ghost Version

5.18.0

Ghost-CLI version:

1.23.1

Node.js Version

v16.17.1

How did you install Ghost?

Followed this guide: How to install & setup Ghost on Ubuntu 16.04, 18.04, 20.04 or 22.04

Database type

MySQL 8

Client Browser & Client OS version

Vivaldi: 5.5.2805.35 / Windows 11

Server OS

  • I use Ubuntu 22.04 LTS!

IP:

  • My server both runs IPv4 and IPv6.

Relevant log / error output


[2022-10-12 13:56:53] INFO "HEAD /" 200 147ms
[2022-10-12 13:56:57] INFO "GET /" 304 110ms
[2022-10-12 13:56:57] INFO "GET /members/api/member/" 204 2ms
[2022-10-12 13:56:57] INFO "POST /members/api/comments/counts/" 200 7ms
[2022-10-12 13:56:58] INFO "GET /ghost/api/content/settings/?key=e7dfb95b57ff10d7ed79546499&limit=all" 304 9ms
[2022-10-12 13:56:58] INFO "GET /ghost/api/content/newsletters/?key=e7dfb95b57ff10d7ed79546499&limit=all" 304 7ms
[2022-10-12 13:56:58] INFO "GET /ghost/api/content/tiers/?key=e7dfb95b57ff10d7ed79546499&limit=all&include=monthly_price,yearly_price,benefits" 304 10ms
[2022-10-12 13:56:59] INFO "GET /OneSignalSDKWorker.js?appId=5ef4c137-7262-41c8-92b9-2e3b6ff6e495?sdkVersion=151514" 304 7ms
[2022-10-12 13:57:01] INFO "GET /signin/" 304 19ms
[2022-10-12 13:57:01] INFO "GET /members/api/member/" 204 1ms
[2022-10-12 13:57:01] INFO "POST /members/api/comments/counts/" 200 5ms
[2022-10-12 13:57:01] INFO "GET /ghost/api/content/settings/?key=e7dfb95b57ff10d7ed79546499&limit=all" 304 27ms
[2022-10-12 13:57:01] INFO "GET /ghost/api/content/newsletters/?key=e7dfb95b57ff10d7ed79546499&limit=all" 304 26ms
[2022-10-12 13:57:01] INFO "GET /ghost/api/content/tiers/?key=e7dfb95b57ff10d7ed79546499&limit=all&include=monthly_price,yearly_price,benefits" 304 30ms
[2022-10-12 13:57:03] INFO "GET /OneSignalSDKWorker.js?appId=5ef4c137-7262-41c8-92b9-2e3b6ff6e495?sdkVersion=151514" 304 6ms
[2022-10-12 13:57:11] ERROR "POST /members/api/send-magic-link/" 500 72ms

NAME: EmailError
CODE: EDNS
MESSAGE: Failed to send email. Reason: Can not use IPv4 addresses with current network.

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error: Can not use IPv4 addresses with current network
    at createMailError (/var/www/ghost/versions/5.18.0/core/server/services/mail/GhostMailer.js:67:12)
    at GetAddrInfoReqWrap.callback (/var/www/ghost/versions/5.18.0/node_modules/nodemailer/lib/shared/index.js:219:35)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:132:8)

Hi :)

I still have this error! I really need help with this!

MESSAGE: Failed to send email. Reason: Can not use IPv4 addresses with current network.

I would check that your DNS is working correctly, and that the server is configured for IPV4. The transactional mail config for Mailgun looks fine.

Hi @mjw

DNS working fine… I have try to change the DNS to google… Both for IPv4 and IPv6

But I still get the error!

BTW: IPv4 and IPv6 working fine

Any ideas???

I still think your network is broken. The error comes from Nodemailer, and it can’t resolve smtp.eu.mailgun.org. From the machine, i.e., ssh, can you ping smtp.eu.mailgun.org? And does it return an IP4 address? Also try ip -4 r to check routing.

As a possible workaround, replace smtp.eu.mailgun.org with the IP address: 35.157.140.183.

Hey @mjw

If i run “dig smtp.eu.mailgun.org” - I get this output:

ghost-mgr@skytower:/var/www/ghost$ dig smtp.eu.mailgun.org

; <<>> DiG 9.18.1-1ubuntu1.2-Ubuntu <<>> smtp.eu.mailgun.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38596
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;smtp.eu.mailgun.org.           IN      A

;; ANSWER SECTION:
smtp.eu.mailgun.org.    60      IN      A       35.156.190.149
smtp.eu.mailgun.org.    60      IN      A       3.122.29.183
smtp.eu.mailgun.org.    60      IN      A       35.157.140.183

;; Query time: 7 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Thu Oct 13 09:44:14 CEST 2022
;; MSG SIZE  rcvd: 96

If I change “smtp.eu.mailgun.org” to “35.157.140.183” - I get this error:

NAME: EmailError
CODE: ESOCKET
MESSAGE: Failed to send email. Reason: Hostname/IP does not match certificate's altnames: IP: 35.157.140.183 is not in the cert's list: .

level: normal

"Please see https://ghost.org/docs/config/#mail for instructions on configuring email."
Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: IP: 35.157.140.183 is not in the cert's list:
    at createMailError (/var/www/ghost/versions/5.18.0/core/server/services/mail/GhostMailer.js:67:12)
    at new NodeError (node:internal/errors:387:5)
    at Object.checkServerIdentity (node:tls:354:12)
    at TLSSocket.onConnectSecure (node:_tls_wrap:1545:27)
    at TLSSocket.emit (node:events:513:28)
    at TLSSocket._finishInit (node:_tls_wrap:949:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:730:12)

if i run “ip -4 r”

ghost-mgr@skytower:/var/www/ghost$ ip -4 r
default via 138.201.226.193 dev eno1 proto static onlink

// Thomas

This seems to point to the problem; you have no private IP4 addresses for the interface.

Can you repeat for IP6, i.e., ip -6 r.

Hi @mjw

Sure:

Here is the command

root@skytower ~ # ip -6 r
::1 dev lo proto kernel metric 256 pref medium
2a01:4f8:173:1e50::/64 dev eno1 proto kernel metric 256 pref medium
fe80::/64 dev eno1 proto kernel metric 256 pref medium
default via fe80::1 dev eno1 proto static metric 1024 pref medium

It looks like you have no IP4 setup on your server.

Hi @mjw

I have other sites that works fine with IPv4 - Im also have some game servers that runs IPv4 without any problems…

### Hetzner Online GmbH installimage
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      addresses:
        - 138.201.226.***/32
        - 2a01:4f8:173:****::2/64
      routes:
        - on-link: true
          to: 0.0.0.0/0
          via: 138.201.226.193
        - to: default
          via: fe80::1
      nameservers:
        addresses:
          - 8.8.8.8
          - 2001:4860:4860::8888
          - 8.8.4.4
          - 2001:4860:4860::8844

Maybe, but I can’t see any private IP4 addresses assigned to the interface, only IP6.

Hi

I contacted umang_io from fiverr.com

After some debugging, he found the error. It was a firewall problem

Now my site works.

1 Like