A mirror of dcurooms found at https://github.com/theycallmemac/dcurooms
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

50 строки
1.5 KiB

  1. import sys
  2. import smtplib
  3. __author__ = "theycallmemac"
  4. __version__ = '2.0.0'
  5. __copyright__ = 'Copyright (c) 2018 theycallmemac'
  6. __license__ = 'GPL-3.0'
  7. class LabBooking(object):
  8. arguments = []
  9. email = ""
  10. password = ""
  11. name = ""
  12. society = ""
  13. def __init__(self, email, password, name, society, arguments):
  14. self.arguments = arguments
  15. self.email = email
  16. self.password = password
  17. self.name = name
  18. self.society = society
  19. def draft(self):
  20. FROM = self.email
  21. TO = ['irene.mcevoy@dcu.ie']
  22. SUBJECT = 'Lab Booking'
  23. BODY = "Just wondering if you could book " + \
  24. self.arguments[0] + " on the " + \
  25. self.arguments[1] + " from " + self.arguments[2][:2] + ":" + \
  26. self.arguments[2][2:] + " to " + self.arguments[3][:2] + ":" + \
  27. self.arguments[3][2:] + " for " + self.society + \
  28. ".\n\nThank you,\n" + self.name + "."
  29. message = """\nFrom: %s\nTo: %s\nSubject: %s\n\n%s""" % (
  30. FROM, ", ".join(TO), SUBJECT, BODY)
  31. return (FROM, TO), message
  32. def send(self, FROM, TO, message):
  33. try:
  34. server = smtplib.SMTP("smtp.gmail.com", 587)
  35. server.ehlo()
  36. server.starttls()
  37. server.login(self.email, self.password)
  38. server.sendmail(FROM, TO, message)
  39. server.close()
  40. return "Your email has been sent."
  41. except BaseException:
  42. return "Email failed to send."