Sending email in python - Did google change something regarding gmail?
<p>I have basic utilities that I have always used for sending emails.<br>
I use gmail to send alerts, notifications etc...</p>

<p>Now, they are ALL breaking with this error and I am wondering if its because of google.</p>

<pre><code>Traceback (most recent call last):
  File "/home/ubuntu/workspace/includes/utility.py", line 44, in &lt;module&gt;
    sendMail('cctest',parms,body='ok - no cc')
  File "/home/ubuntu/workspace/includes/utility.py", line 38, in sendMail
    server.sendmail(fromaddr, toaddrs, message)
  File "/usr/lib/python2.7/smtplib.py", line 700, in sendmail
    self.rset()
  File "/usr/lib/python2.7/smtplib.py", line 441, in rset
    return self.docmd("rset")
  File "/usr/lib/python2.7/smtplib.py", line 366, in docmd
    return self.getreply()
  File "/usr/lib/python2.7/smtplib.py", line 343, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
</code></pre>

<p>Below is a sample code I typically use.  I cant even remember the last time I modified the code.  </p>

<pre><code>def sendMail(subject,parms,body=None,cc=None):

    import smtplib
    import email.utils
    from email.mime.text import MIMEText
    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEBase import MIMEBase
    from email import Encoders

    toaddr = parms['email_to']
    fromaddr = parms['email_from']
    message_subject = subject
    message_text = body
    if cc:
        message = "From: %s\r\n" % fromaddr + "To: %s\r\n" % toaddr + "CC: %s\r\n" % ",".join(cc) + "Subject: %s\r\n" % message_subject + "\r\n" + message_text
        toaddrs = [toaddr] + cc #+ bcc
    else:
        message = "From: %s\r\n" % fromaddr + "To: %s\r\n" % toaddr + "Subject: %s\r\n" % message_subject + "\r\n" + message_text
        toaddrs = [toaddr]

    server = smtplib.SMTP('smtp.gmail.com',587)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(fromaddr,parms['email_password'])
    server.sendmail(fromaddr, toaddrs, message)
    server.quit()

    print "Email sent..."
</code></pre>
