import smtplib
fromaddr = 'FROM'
toaddr = 'TO'
subj = 'Test email'
msg_txt = bytes('body','utf-8')
msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (fromaddr, toaddr, subj, msg_txt)
username = 'username'
password = 'password'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddr, msg)
server.quit()