Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mailsmtp_init_with_ip for IPv6 on Linux #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

d99kris
Copy link
Contributor

@d99kris d99kris commented May 27, 2023

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:

  1. 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().

  2. 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:

501-5.5.4 HELO/EHLO argument "[2400:e800:2000:b00:4000:0:600:0%808590000]"
501-5.5.4 invalid, closing connection.
501 5.5.4 https://support.google.com/mail/?p=helo a14-20020a62bd0e000000b0064d413caea6sm3299641pff.179 - gsmtp

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.

d99kris added a commit to d99kris/nmail that referenced this pull request Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant