title: Python emailer not working
body: <p>I am trying to write a Python class that will send emails using Python's <code>smtplib</code> libraries. I got it to work with standard Gmail, but am having trouble getting the config to work with other accounts.</p>
  
  <p>Emailer Class config and send method:</p>
  
  <pre><code>def configure(self,  serverLogin, serverPassword, fromAddr, toAddr, serverHost='mail.myserver.edu', serverPort=465):
      self.server=smtplib.SMTP(serverHost,serverPort) #set the server host/port - currently configured for gmail
      self.server.ehlo()
      self.server.starttls()
      self.server.ehlo()
      self.server.login(serverLogin, serverPassword)  #login to senders email
      self.fromAddr = fromAddr
      self.toAddr = toAddr
  
  def send(self):
      msgText = email.MIMEText.MIMEText("\n".join(self.message))
      self.msg.attach(msgText) 
      print "Sending email to %s " % self.toAddr
      text = self.msg.as_string() #conver the message contents to string format
      self.server.sendmail(self.fromAddr, self.toAddr, text)  #send the email
  </code></pre>
  
  <p>Emailer Test method:</p>
  
  <pre><code>def test(self):
      message = "Like a boss"  #body message of the email
      attachment = ["/Desktop/testImage2"]    #list of attachments
      image = ["/Desktop/testImage2"]
      emailer = Emailer() 
      emailer.addAttachment(attachment)
      emailer.addToMessage(message,image)
      emailer.setSubject("Python Test")
      emailer.configure(serverLogin="loginname", serverPassword="password", fromAddr="myaddr@myserver.edu", toAddr=["otheraddr@gmail.com"])
      emailer.send()
  </code></pre>
  
  <p>I set up my email account successfully in other mail clients (like Outlook) using this information, and the classes work just fine when I use <code>serverHost = 'smtp.gmail.com'</code> and <code>serverPort = 587</code>.  However, when I run the <code>test()</code> class in the terminal with my non-Gmail server information, the code appears to hang on this bit:</p>
  
  <pre><code>/Users/anaconda/lib/python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, timeout)
  254         self.esmtp_features = {}
  255         if host:
  --&gt; 256             (code, msg) = self.connect(host, port)
  257             if code != 220:
  258                 raise SMTPConnectError(code, msg)
  
  /Users/anaconda/lib/python2.7/smtplib.pyc in connect(self, host, port)
  315             print&gt;&gt;stderr, 'connect:', (host, port)
  316         self.sock = self._get_socket(host, port, self.timeout)
  --&gt; 317         (code, msg) = self.getreply()
  318         if self.debuglevel &gt; 0:
  319             print&gt;&gt;stderr, "connect:", msg
  
  /Users/anaconda/lib/python2.7/smtplib.pyc in getreply(self)
  359         while 1:
  360             try:
  --&gt; 361                 line = self.file.readline(_MAXLINE + 1)
  362             except socket.error as e:
  363                 self.close()
  
  /Users/anaconda/lib/python2.7/socket.pyc in readline(self, size)
  474             while True:
  475                 try:
  --&gt; 476                     data = self._sock.recv(self._rbufsize)
  477                 except error, e:
  478                     if e.args[0] == EINTR:
  
  KeyboardInterrupt:
  </code></pre>
  
  <p>Can anyone tell me why it's getting stuck here?</p>