# Sending email : "Error can not use ipv4 addresses with current network"

**URL:** <https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598>\
**Category:** General\
**Created:** [12 September 2022 09:25 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598 "2022-09-12T09:25:08Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![RandomSporadicProjs](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@RandomSporadicProjs](https://discourse.nodered.org/u/RandomSporadicProjs)\
**Post date:** [5 October 2022 14:00 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/22 "2022-10-05T14:00:37Z")

</div>

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](http://smtp.gmail.com) fixed it.

I went digging and found the code that triggers the error message here  
[nodemailer/index.js at master · nodemailer/nodemailer · GitHub](https://github.com/nodemailer/nodemailer/blob/master/lib/shared/index.js) @ line 219

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

> <https://github.com/nodemailer/nodemailer/issues/1371>
>
> Hi everyone, i tried for several hours checking on issues and internet articles …but i can't seem to find a good solution.
> The error is the following while trying to send a simple email:
> \`\`\`
> Error: queryA EREFUSED smtp.office365.com
> at QueryReqWrap.onresolve \[as oncomplete\] (dns.js:203:19) { 
> errno: 'EREFUSED', 
> code: 'EDNS',
> syscall: 'queryA',
> hostname: 'smtp.office365.com',
> command: 'CONN'
> }
> \`\`\`
> 
> The same code works locally but not on a custom VPS/server. At first i checked my DNS settings and firewall and they were all fine.
> After reading some issues i found one guy recommending a downgrade to version 4.7.0 .I did it and it worked, but i don't want to miss the newest updates and npm warns me of a critical vulnerability for versions before 6.6.0 . 
> 
> What can i do to prevent this error without changing email provider or nodemailer version?

And an earlier closed issue about accessing local interfaces which was added to the code

> <https://github.com/nodemailer/nodemailer/issues/1437>
>
> BACKGROUND:
> 
> \- sometimes, virtualized servers or environments, make use of com…mon network interfaces (i.e. FreeBSD jails), provided by the hosting system.
> \- it is common, to use a cloned loopback interface of the parent system for relaying traffic in and out to the child systems
> \- In those cases the child has an interface, that, if you are running node.js on that child and use \`os.networkInterfaces()\`, is is marked as "internal" (which is correct, but for the child its the only interface to the external world and as such is "external")
> \- We need to have an option to tell nodemailer, that it can also make use of internal interfaces.
> 
> IS
> \- using nodemailer in the described setup, the following error is thrown: 
> \`\`\`
> Can not use IPv(4|6) addresses with current network
> =\> lib/shared/index.js, 210
> \`\`\` 
> 
> SHOULD
> \- a configuration should allow to avoid testing, if os network interfaces are internal
> \`\`\`javascript
> const mailConfig = {
> pool: true,
> host: 'my.funyy.mailhost.com',
> secure: true,
> allowInternalNetworkInterfaces: true,
> auth: {
> user: process.env\['SMTP\_USER'\],
> pass: process.env\['SMTP\_PWD'\]
> },
> }
> \`\`\`
> 
> \- This option should then be considered in function \`isFamilySupported(family)\` in \`lib/shared/index.js\`
> \`\`\`javascript
> const isFamilySupported = family =\> {
> const familySupported =
> // crux that replaces Object.values(networkInterfaces) as Object.values is not supported in nodejs v6
> Object.keys(networkInterfaces)
> .map(key =\> networkInterfaces\[key\])
> // crux that replaces .flat() as it is not supported in older Node versions (v10 and older)
> .reduce((acc, val) =\> acc.concat(val), \[\])
> .filter(i =\> !i.internal) // this should optionally be not filtered
> .filter(i =\> i.family === 'IPv' + family || i.family === family).length \> 0;
>   
> return familySupported;
> };

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](http://smtp.gmail.com) just in case

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 December 2022 14:01 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/23 "2022-12-04T14:01:11Z")

</div>

Closed on 4 December 2022 14:01 UTC

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 13:28 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/24 "2023-03-26T13:28:57Z")

</div>

Opened on 26 March 2023 13:28 UTC



---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 13:33 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/25 "2023-03-26T13:33:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 14:17 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/26 "2023-03-26T14:17:46Z")

</div>

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.

I have submitted an issue. [Sending email "Error: Can not use IPv4 addresses with current network" · Issue #4114 · node-red/node-red · GitHub](https://github.com/node-red/node-red/issues/4114)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 14:19 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/27 "2023-03-26T14:19:48Z")

</div>

Several possible answers here - feel free to try and report back

> <https://serverfault.com/questions/867830/systemd-start-service-only-after-dns-is-available>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 14:41 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/28 "2023-03-26T14:41:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 15:26 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/29 "2023-03-26T15:26:27Z")

</div>

So when the problem happens does it correct itself after a time ? IE once the DNS service is running then it works ok ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 15:27 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/30 "2023-03-26T15:27:26Z")

</div>

No, it is necessary to restart node-red to make it recover.

---

<div class="post-metadata">

**Author:** ![RandomSporadicProjs](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@RandomSporadicProjs](https://discourse.nodered.org/u/RandomSporadicProjs)\
**Post date:** [26 March 2023 15:33 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/31 "2023-03-26T15:33:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 15:34 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/32 "2023-03-26T15:34:15Z")

</div>

but pinging the address (by name) does work presumably ?  
And is it just sending ? can you retrieve email ok ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 15:48 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/33 "2023-03-26T15:48:21Z")

</div>

> [@dceejay](#):
>
> pinging the address (by name) does work presumably ?

Yes.

I don't know whether receiving works, I am not setup to receive email.

It does appear to be related to DNS, as others reported earlier, the problem does not appear if I use the IP address of the server.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 16:23 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/34 "2023-03-26T16:23:07Z")

</div>

The nodemailer library does seem to suffer - [GitHub - nodemailer/nodemailer: ✉️ Send e-mails with Node.JS – easy as cake!](https://github.com/nodemailer/nodemailer#i-have-issues-with-dns--hosts-file) - I'm not sure what we can do to help them fix it.

---

<div class="post-metadata">

**Author:** ![julienD](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@julienD](https://discourse.nodered.org/u/julienD)\
**Post date:** [26 March 2023 18:03 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/35 "2023-03-26T18:03:53Z")

</div>

Hi, thanks for your research.  
My pi is connected with Ethernet.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 19:05 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/36 "2023-03-26T19:05:29Z")

</div>

> [@dceejay](#):
>
> pinging the address (by name) does work presumably

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?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 19:33 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/37 "2023-03-26T19:33:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 March 2023 20:44 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/38 "2023-03-26T20:44:14Z")

</div>

I have tried the http request node and it behaves as expected. Recovering when the network is reconnected.

Would it be trivial for someone who knows what they are doing to knock up a function node using nodejs to do a dns lookup?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 March 2023 21:32 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/39 "2023-03-26T21:32:18Z")

</div>

yes

```auto
[{"id":"d1a5055351b39cd2","type":"inject","z":"fe51cb720c42b6e9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"smtp.gmail.com","payloadType":"str","x":200,"y":450,"wires":[["fd28f1d954d39f50"]]},{"id":"fd28f1d954d39f50","type":"function","z":"fe51cb720c42b6e9","name":"function 1","func":"dns.resolve4(msg.payload, (\n err, address) => node.warn('resolve4: '+ address)\n);\ndns.resolve6(msg.payload, (\n err, address) => node.warn('resolve6: '+ address)\n);\ndns.lookup(msg.payload, (\n err, address) => node.warn('lookup: '+ address)\n);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"dns","module":"dns"}],"x":435,"y":450,"wires":[[]]}]

```

and see docs for other options [DNS | Node.js v18.15.0 Documentation](https://nodejs.org/docs/latest-v18.x/api/dns.html#dnsresolve4hostname-options-callback)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 March 2023 09:25 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/40 "2023-03-27T09:25:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 March 2023 19:38 UTC](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598/41 "2023-03-27T19:38:29Z")

</div>

bumped email node version. (It also now support OAuth authentication thanks to an incoming PR which we were testing)

[Previous page](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598.md?page=1)

[Next page](https://discourse.nodered.org/t/sending-email-error-can-not-use-ipv4-addresses-with-current-network/67598.md?page=3)
