Hi!
Firstly, thanks for the great work on this library! I've been using it in my TUI email client nmail for 4 years and it's been very solid to work with.
Now to my problem: It appears that mailsmtp_init_with_ip(smtp, 1) (i.e. using ip address instead of hostname) fails on Linux when socket address is of IPv6 type.
There are two reasons for this:
getnameinfo() is called with sizeof(addr) (which is 16) so this call fails with EAI_FAMILY (-6) for IPv6 addresses. We can fix this by using addr_len which is populated with the actual address length by getsockname().
The host address populated by getnameinfo() may be suffixed by % and a network interface specifier, and at least Gmail does not accept this format, and returns an error like:
Hi! Firstly, thanks for the great work on this library! I've been using it in my TUI email client nmail for 4 years and it's been very solid to work with.
Now to my problem: It appears that
mailsmtp_init_with_ip(smtp, 1)
(i.e. using ip address instead of hostname) fails on Linux when socket address is of IPv6 type.There are two reasons for this:
getnameinfo()
is called withsizeof(addr)
(which is 16) so this call fails withEAI_FAMILY
(-6) for IPv6 addresses. We can fix this by usingaddr_len
which is populated with the actual address length bygetsockname()
.The host address populated by
getnameinfo()
may be suffixed by%
and a network interface specifier, and at least Gmail does not accept this format, and returns an error like:This can be fixed by simply dropping the interface specifier from the IPv6 address.
I've tested the patch on IPv6 and IPv4 on Linux.