sentMail.py 689 B

1234567891011121314151617
  1. def sendStarttls(host, sendingMail, receivingMail, password, message="",
  2. subject="", port=587, cc=[], bcc=[]):
  3. context = ssl.create_default_context()
  4. if type(cc) is not str:
  5. cc = ",".join(cc)
  6. if type(bcc) is not str:
  7. bcc = ",".join(bcc)
  8. utf8Message = ("Subject: " + subject + "\nCC: " + cc + "\nBCC: " + bcc +
  9. "\n\n" + message)
  10. decoded = utf8Message.encode('cp1252').decode('utf-8')
  11. with smtplib.SMTP(host, port) as serverConnection:
  12. serverConnection.starttls(context=context)
  13. serverConnection.login(sendingMail, password)
  14. serverConnection.sendmail(sendingMail, receivingMail, decoded)