From 58ebd3bc0f00c532e97e9a5571471ffab87934ba Mon Sep 17 00:00:00 2001 From: AL-LCL Date: Fri, 19 May 2023 10:39:49 +0200 Subject: GOD-VIEW --- server/email.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 server/email.py (limited to 'server/email.py') diff --git a/server/email.py b/server/email.py new file mode 100644 index 0000000..add33c4 --- /dev/null +++ b/server/email.py @@ -0,0 +1,58 @@ +''' + To open an secure SMTP connection to the + Gmail server, format & finally send out + the email. + + Verified: 2021 February 7 + * Follows PEP8 + * Tested Platforms + * Windows 10 +''' + +from server.state import ServerStatic +from server.error import ServerError + +import smtplib +import email + + +class Email: + + __SMTP_SERVER = ('smtp.gmail.com', 465) + __EMAIL_CSS = ('font-family: Arial, Helvetica, sans-serif;' + 'background-color: rgb(31, 93, 117);' + 'color: rgb(255, 255, 255);' + 'font-size: 0.75rem;' + 'font-weight: 100;' + 'padding: 2rem;') + + def __init__(self, sender, password, recievers): + self.__sender = sender + self.__password = password + self.__recievers = recievers + + @ServerError.quiet + def send(self, subject, title, body): + with smtplib.SMTP_SSL(*Email.__SMTP_SERVER) as smtp: + smtp.login(self.__sender, self.__password) + smtp.send_message(self.__email(subject, title, body)) + + return True + + def __email(self, subject, title, body): + message = email.message.EmailMessage() + message['Subject'] = subject + message['From'] = self.__sender + message['To'] = self.__recievers + message.set_content(''' +
+ {} {} {} +
+ {} +
+ '''.format(Email.__EMAIL_CSS, + ServerStatic.NAME, + ServerStatic.SEPERATOR, + title, body), subtype='html') + + return message -- cgit v1.2.3