Long Standing SMTP Issue With SSL... Nailed?

I think I found a way out of a long standing SMTP issue with Mastodon, and with Ruby OpenSSL in general.

You may have seen, witnessed, or suffered from that kind of error:

 OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 peeraddr=YOUR_MAILER_IP:465 state=error: unexpected eof while reading

There are plenty of reports and unsolved but closed bugs, with people telling they have solved the issue but it’s not always clear how. Most of the time, the recommendation is to remove SSL certificate verification. Even bugs in the OpenSSL library seem to be closed without much of a resolution.

Today I had to fix email on my Mastodon instances, so I tested all kinds of combinations. I did not want to not verify certificates (and it didn’t work anyway), so I had to find something else. In the end, the solution I found that magically fixed the mail, was to force Rails to use IPv4 instead of IPv6. Weird? Yes, but it just works.

Simply adding the IPv4 of my smarthost in /etc/hosts reopened the mail delivery!

Can you confirm that it works, and that IPv6 is an issue for Ruby’s OpenSSL library?

I’m posting it here because I never found this answer to an issue that seems to be affecting many setups, with a badly understood situation and not so recommendable fixes.

1 Like