def send_mail(to, subject, text):
    logger.debug("sending flowspace approval email to: %s"%to)
    msg = MIMEText(text)

    msg['From'] = EMAIL_HOST_USER
    msg['To'] = to
    msg['Subject'] = subject

    [username,atsign,domain] = EMAIL_HOST_USER.partition("@")
    if (len(atsign) == 0):
        return False

    mailServer = smtplib.SMTP(EMAIL_HOST,EMAIL_PORT)
    mailServer.ehlo()
    mailServer.starttls()
    mailServer.ehlo()
    mailServer.login(username, EMAIL_HOST_PASSWORD)
    mailServer.sendmail(EMAIL_HOST_USER, to, msg.as_string())
    # Should be mailServer.quit(), but that crashes...
    mailServer.close()
    return True
Taken from http://kutuma.blogspot.com/2007/08/sending-emails-via-gmail-with-python.html
dataset/ETHPy150Open fp7-ofelia/ocf/optin_manager/src/python/openflow/optin_manager/admin_manager/helper.py/send_mail