Just to add that I've just experienced this too yesterday.
I have 2 subnets and a rpi with node-red on each (both nr 3.0.2 and nodejs 16.17.1) one of my rPis was giving me this error, and the other not. Both could reach the internet. For me switching to the IP address of smtp.gmail.com fixed it.
I looked at the changelog for this file and tried to see if undoing some of the changes resolved the issue but I was unsuccessful.
The error is raised in a closed issue, though just 22 days ago with someone else experiencing it
And an earlier closed issue about accessing local interfaces which was added to the code
I've not managed to get to the bottom of this, but today when I've begun to look at it again - it is all working just fine on both machines again. I'm just wondering if somewhere there was some bad dns data that has expired and been refreshed, or perhaps my pihole interfered (recently updated) but I've not found any logs showing anything was blocked ---hmm.
Since this fails relatively silently I've got 2 nodes for an important email alert flow, one with the IP and one smtp.gmail.com just in case
I am re-opening this as it is still a live issue.
I think that I may have determined the trigger. I think it can happen if node red starts up before the network is up and running, which is often the case if using wifi. @julienD@sand_man@RandomSporadicProjs were you using wifi when this problem occurred?
I am doing some further tests to see if I can reliably create the problem.
I am able to replicate it reliably on my system. I I disconnect the network and restart node red, then connect the network and try to send an email then I get the ipv4 error.
Several possible answers here - feel free to try and report back
We already had an optional line in the service file in case someone needs to wait for time sync first... and indeed that may require DNS to work - so that may fix both situations... but is not a panacea as some users may not have internet access.
I though the had also determined it was to do with the fact node18 prioritises IPv6 over IPv4, and that was going to be re-visited.
I think I would class those as workarounds rather than answers. Hopefully now that (for me at least) the problem can be reproduced, the underlying cause can be found.
Thanks for the info - though in my case both of the RPis I run are connected via ethernet - though my main one is also has pihole on it so I'll investigate the DNS availability check mentioned later in this thread
I realised that your question and my answer were ambiguous. It could have meant ping in a command or ping in node red. In fact both of them recover when the network is restored, unlike the email node. Do you know whether node-red-node-ping uses nodejs to do the DNS lookup?
If it doesn't use nodejs do do the dns is there an simple way to find out whether it is the nodejs DNS that is broken or if it is specific to the email node?
Good thought. And no Sadly the ping node does in fact just shell out to the is ping command. So we need to find another node. I guess http request would.
That works as I would expect, recovering after the network is restored to give the same as it does when the network was connected on restart, undefined for ipv6 and the correct address for ipv4 and for lookup.
Do you know if there is a reason that node-red-node-email is not pulling in the latest version of nodemailer (6.8.0 instead of 6.9.1) and smtp-server (which is pulled in by the node) is using nodemailer 6.7.3, which is earlier than the version fixing at least one of the bugs which have shown the same symptom, mentioned by @RandomSporadicProjs in post #21
Perhaps all it needs is an update of package.json on those.