custom_email.py 871 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/python3
  2. import smtplib, ssl
  3. class simplemail:
  4. def __init__(self, subject, body, sendto = [], user='stagl.mike@gmail.com', password='cherokee2'):
  5. self.subject = subject
  6. self.body = body
  7. self.sendto = sendto
  8. self.user = user
  9. self.password = password
  10. def sendmail(self):
  11. email_text = """\
  12. From: %s
  13. To: %s
  14. Subject: %s
  15. %s
  16. """ % (self.user, self.sendto, self.subject, self.body)
  17. try:
  18. server_ssl = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  19. server_ssl.ehlo()
  20. server_ssl.login(self.user, self.password)
  21. server_ssl.sendmail(self.user, self.sendto, email_text)
  22. server_ssl.close()
  23. except Exception as e:
  24. print('Something went wrong...', e)
  25. #myemail = simplemail('Test to multiple addrrsses', 'This is a test to two people.', ['stagl.mike@gmail.com', 'M_Stagl@hotmail.com'])
  26. #myemail.sendmail()