title: Python socket slow to connect for SMTP after multiple successful connections
body: <p>I have a script that is emailing out PDFs to our clients and am having an issue where when I start the script, it sends up to three PDFs and then it starts to take 1-2 minutes for each subsequent email to send out. I can halt the script and start over in a few minutes, allowing the same result where three go out and the rest are molasses.</p>
  
  <p>I've narrowed it down to a server problem, with near certainty, but I don't know what it could be. I have two servers, one from an old AWS account, and that one can send emails quickly over and over again. The new AWS account server can do three. When I interrupt the program, I know that it is stuck connecting because this is the trace:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./test_reports.py", line 202, in &lt;module&gt;
      send_email(advertiser_email, sales_email, emailSubject, emailBody, fname, sendEmail=True)
    File "./test_reports.py", line 158, in send_email
      smtp = smtplib.SMTP('email-smtp.us-east-1.amazonaws.com')
    File "/usr/lib64/python3.5/smtplib.py", line 251, in __init__
      (code, msg) = self.connect(host, port)
    File "/usr/lib64/python3.5/smtplib.py", line 335, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File "/usr/lib64/python3.5/smtplib.py", line 306, in _get_socket
      self.source_address)
    File "/usr/lib64/python3.5/socket.py", line 702, in create_connection
      sock.connect(sa)
  KeyboardInterrupt
  </code></pre>
  
  <p>If I run strace on the python process while it is trying to send, I get this:</p>
  
  <pre><code>connect(4, {sa_family=AF_INET, sin_port=htons(25), sin_addr=inet_addr("54.243.225.221")}, 16)
  </code></pre>
  
  <p>I now have a test script where it only sends an email, and I notice I can run that three times as well before it takes forever to send. I am thinking it is some sort of rate limit on the server, but I'm not sure where to look now.</p>