def sendEmail(SUBJECT, BODY, TO, FROM, SENDER, PASSWORD, SMTP_SERVER):
 for body_charset in ('US-ASCII', 'ISO-8859-1', 'UTF-8'):
  try:
   BODY.encode(body_charset)
  except UnicodeError:
   pass
  else:
   break
 msg = MIMEText(BODY.encode(body_charset), 'html', body_charset)
 msg['From'] = SENDER
 msg['To'] = TO
 msg['Subject'] = SUBJECT
 SMTP_PORT = 587
 session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
 session.starttls()
 session.login(FROM, PASSWORD)
 session.sendmail(SENDER, TO, msg.as_string())
 session.quit()

def sendEmail ( SUBJECT , BODY , TO , FROM , SENDER , PASSWORD , SMTP_SERVER ) : for body_charset in ( 'US-ASCII' , 'ISO-8859-1' , 'UTF-8' ) : try : BODY . encode ( body_charset ) except UnicodeError : pass else : break msg = MIMEText ( BODY . encode ( body_charset ) , 'html' , body_charset ) msg [ 'From' ] = SENDER msg [ 'To' ] = TO msg [ 'Subject' ] = SUBJECT SMTP_PORT = 587 session = smtplib . SMTP ( SMTP_SERVER , SMTP_PORT ) session . starttls ( ) session . login ( FROM , PASSWORD ) session . sendmail ( SENDER , TO , msg . as_string ( ) ) session . quit ( )
sends an html email .