title: Sending email with Python smtplib doesn't seem to work?
body: <p>I'm trying to send email using the Python smtplib. I have a working setup with a gmail address, but I now want to use a custom email address (noreply@mydomain.com). So I created the desired email address and tested it in Thunderbird with the following settings:</p>
  
  <pre><code>Servername: securemail.hostingxs.nl
  Port: 578
  Username: noreplymydomaincom
  Authentication method: Normal password
  Connection security: STARTTLS
  </code></pre>
  
  <p>So I tried the following from the command line:</p>
  
  <pre><code>&gt;&gt;&gt; import smtplib
  &gt;&gt;&gt; from email import Encoders
  &gt;&gt;&gt; smtpServer = smtplib.SMTP('securemail.hostingxs.nl', 587)
  &gt;&gt;&gt; smtpServer.ehlo()
  (250, 'securemail.hostingxs.nl Hello ec2-52-22-82-231.eu-central-1.compute.amazonaws.com [52.22.82.231], pleased to meet you\nENHANCEDSTATUSCODES\nPIPELINING\nEXPN\nVERB\n8BITMIME\nSIZE\nDSN\nAUTH LOGIN
  PLAIN DIGEST-MD5 CRAM-MD5\nSTARTTLS\nDELIVERBY\nHELP')
  &gt;&gt;&gt; smtpServer.starttls()
  (220, '2.0.0 Ready to start TLS')
  &gt;&gt;&gt; smtpServer.login('noreplymydomaincom', 'mypassword')  # I triple checked the password and copy pasted it between the command line and Thunderbird
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/smtplib.py", line 622, in login
      raise SMTPAuthenticationError(code, resp)
  SMTPAuthenticationError: (535, '5.7.0 authentication failed')
  &gt;&gt;&gt;
  </code></pre>
  
  <p>Does anybody know what I could possibly be doing wrong here? All tips are welcome!</p>
  
  <p>[EDIT]</p>
  
  <p>I tried using different server names, and when using <code>smtp.mydomain.com</code> I get a bit further, but I'm unable to send the actual email:</p>
  
  <pre><code>&gt;&gt;&gt; smtpServer = smtplib.SMTP('smtp.mydomain.com', 587)
  &gt;&gt;&gt; smtpServer.ehlo()
  (250, 'shared3.hostingxs.nl Hello ec2-52-28-82-231.eu-central-1.compute.amazonaws.com [52.28.82.231],
   pleased to meet you\nENHANCEDSTATUSCODES\nPIPELINING\nEXPN\nVERB\n8BITMIME\nSIZE\nDSN\nAUTH LOGIN PL
  AIN\nSTARTTLS\nDELIVERBY\nHELP')
  &gt;&gt;&gt; smtpServer.starttls()
  (220, '2.0.0 Ready to start TLS')
  &gt;&gt;&gt; smtpServer.login('noreplymydomaincom', 'ourpassword')
  (235, '2.0.0 OK Authenticated')
  &gt;&gt;&gt; smtpServer.ehlo()
  (250, 'shared3.hostingxs.nl Hello ec2-52-28-82-231.eu-central-1.compute.amazonaws.com [52.28.82.231],
   pleased to meet you\nENHANCEDSTATUSCODES\nPIPELINING\nEXPN\nVERB\n8BITMIME\nSIZE\nDSN\nAUTH LOGIN PL
  AIN\nDELIVERBY\nHELP')
  &gt;&gt;&gt; recipients = ['mypersonalemail@gmail.com']
  &gt;&gt;&gt; from email.mime.text import MIMEText
  &gt;&gt;&gt; from email.mime.multipart import MIMEMultipart
  &gt;&gt;&gt; from email.mime.base import MIMEBase
  &gt;&gt;&gt; from email import Encoders
  &gt;&gt;&gt; msg = MIMEMultipart()
  &gt;&gt;&gt; msg['From'] = 'Our company name &lt;noreply@mydomain.com&gt;'
  &gt;&gt;&gt; msg['To'] = ', '.join(recipients)
  &gt;&gt;&gt; msg['Subject'] = 'TEST FROM THE COMMAND LINE'
  &gt;&gt;&gt; msg.attach(MIMEText('this is the body text'))
  &gt;&gt;&gt; smtpServer.sendmail('noreplymydomaincom', 'mypersonalemail@gmail.com', msg.as_string())
  Traceback (most recent call last):
    File "&lt;input&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.7/smtplib.py", line 728, in sendmail
      (code, resp) = self.mail(from_addr, esmtp_opts)
    File "/usr/lib/python2.7/smtplib.py", line 481, in mail
      return self.getreply()
    File "/usr/lib/python2.7/smtplib.py", line 368, in getreply
      raise SMTPServerDisconnected("Connection unexpectedly closed")
  SMTPServerDisconnected: Connection unexpectedly closed
  </code></pre>
  
  <p>Anybody any tips? I'm really stuck here..</p>