Nodemailer: Feature Request: Make it possible to prefer IPv6 over IPv4

Created on 25 Apr 2020  Â·  9Comments  Â·  Source: nodemailer/nodemailer

Please fill the following questionnaire about your issue:

  1. What kind of issue are you reporting?
  2. [ ] A bug in Nodemailer
  3. [ ] A bug in a plugin of Nodemailer (eg. issues with nodemailer-sendgrid)
  4. [X] Feature request
  5. [ ] Looking for help to resolve some kind of problem with Nodemailer

  6. Are you listed as a sponsor of Nodemailer project (see Sponsors button above)?

  7. [ ] Yes. Sponsors get priority support
  8. [X] No. Unless it is a bug in Nodemailer you might find support from public forums like StackOverflow.

  9. State your problem here:

See PR #1041 for background information on how Nodemailer resolves SMTP hostnames today, it explicitly prefers IPv4 over IPv6 in case both are available.

In a network environment such as mine, it would however be preferrable to use IPv6 even when IPv4 is available. As Nodemailer has its own logic for this, it'd be very nice if this logic was made configurable.

(I'd be happy to write a patch for this, if you'd like me to.)

All 9 comments

If you prefer a specific IP address then you can provide it directly as host and set the hostname to tls.servername as this way Nodemailer skips DNS resolving step entirely.

Well, I'd really prefer to still use the resolver and not hardcode the IP-address (for all the obvious reasons).

can you elaborate on this please?
@roubert
how would that work here?
this.transporter = nodemailer.createTransport({ host: process.env.MAIL_HOST, port: process.env.MAIL_PORT,

If the Nodemailer project would want to keep current default behaviour unchanged but allow a configuration flag to prefer IPv6 even when IPv4 is available, then I'd suggest adding a configuration option right next to host and port there, which then gets passed from createTransport() to SMTPTransport() to SMTPConnection() to resolveHostname() where it is used to then reverse the order of the calls to resolver(4, …) and resolver(6, …).

I am about to have a look into that soon.. Or do you have a PR for that you suggest?
I am deploying in an ipv6 only ecosystem, and just fails to connect using the port as IP suffix

I haven't written a single line of code for this yet, but in case the maintainers find the idea sound but can't find the time to do it themselves, I could volunteer to do it (but it's of course much more convenient for me if someone else does it instead).

@andris9 I tried to pass it from custom lookup , seems tough one, it gets to do a lookup with the ipv6 and the brackets I added
getaddrinfo ENOTFOUND [240b:c
the lookup was not a problem before, but the port assignment :(
...:f220:70e:25
same thing seems to happen if we set the host as ipv6 and the tls: { servername: process.env.MAIL_HOST },

Also adding the connections as connection string, ends up with the same behaviour

│ [ connectionstring:  smtp://[240b:c0e0:xxx:2:0:70e]:25  

│ result: 
connect ECONNREFUSED 240b:c0e0:xxx:2:0:70e:25                            
│     Error: connect ECONNREFUSED 240b:c0e0:xxx:2:0:70e:25                                               

seems to be working regardless the print, once the ports were configured correctly, sort of wrong error print, but worked ok :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Meenakshi14 picture Meenakshi14  Â·  13Comments

jonathanong picture jonathanong  Â·  12Comments

miiiku picture miiiku  Â·  13Comments

hughht5 picture hughht5  Â·  18Comments

murvinlai picture murvinlai  Â·  14Comments