cisagov / trustymail

Scan domains and return data based on trustworthy email best practices
Creative Commons Zero v1.0 Universal
185 stars 31 forks source link

Force smtplib to use IPv4 addresses #115

Closed jsf9k closed 5 years ago

jsf9k commented 5 years ago

@climber-girl noticed some cases where the text [Errno 97] Address family not supported by protocol appears in the trustymail output. I dug into this, and it appears to happen because, when given a hostname to connect to, smtplib asks DNS for all A and AAAA records, tries them in succession, and uses the first one that works.

When running trustymail in AWS Lambda (at least in my VPC, which doesn't support IPv6) the [Errno 97] Address family not supported by protocol error appears when an IPv6 connection is attempted. This makes the connection attempt fail hard, and the other IP addresses returned by DNS are not even attempted.

To get around this, I explicitly get an IPv4 address for the hostname and pass that to smtplib instead. This way no IPv6 connections are ever attempted.