From 5cfeb8762765e448ca024475205440c779a739cb Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Wed, 3 May 2023 23:01:57 +0700 Subject: [PATCH] Add email smtp library in core directory --- config/directory.py | 1 + config/template.py | 7 +++++ core/mailme.py | 23 ++++++++++++++++ static/email/verification.html | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 core/mailme.py create mode 100644 static/email/verification.html diff --git a/config/directory.py b/config/directory.py index 7b8e3d5..2301cda 100644 --- a/config/directory.py +++ b/config/directory.py @@ -3,6 +3,7 @@ import os # For templating page = "static/page" template = "static/template" +email = "static/email" # For route dirconfig = { diff --git a/config/template.py b/config/template.py index a782bdc..1d82e1f 100644 --- a/config/template.py +++ b/config/template.py @@ -7,6 +7,7 @@ class main: # Declare a variables self.html_page = html.main.get_html(directory.page) self.html_template = html.main.get_html(directory.template) + self.html_email = html.main.get_html(directory.email) def user(self, page): params_list = { @@ -16,3 +17,9 @@ class main: "container" : self.html_page [ page+".html" ] } return params_list + + def verification(self): + params_list = { + "template" : self.html_email ["verification.html" ] + } + return params_list diff --git a/core/mailme.py b/core/mailme.py new file mode 100644 index 0000000..2e83e57 --- /dev/null +++ b/core/mailme.py @@ -0,0 +1,23 @@ +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +import smtplib + +def smtp(config): + + msg = MIMEMultipart('alternative') + msg['Subject' ] = config['subject' ] + msg['From' ] = config['from' ] + msg['To' ] = config['to' ] + + part1 = MIMEText(config['text'], 'plain') + part2 = MIMEText(config['html'], 'html' ) + + msg.attach(part1) + msg.attach(part2) + + smtp_server = smtplib.SMTP(config['server']['host'], config['server']['port']) + smtp_server.ehlo() + smtp_server.starttls() + smtp_server.login( config['login']['email'], config['login']['password'] ) + smtp_server.sendmail('&&&&&&', email, msg.as_string() ) + smtp_server.quit() diff --git a/static/email/verification.html b/static/email/verification.html new file mode 100644 index 0000000..76bbdf9 --- /dev/null +++ b/static/email/verification.html @@ -0,0 +1,50 @@ + + + + + + +
+ + + + + + +
+
+
+
+ + + + + + +
+ Verify Account +
Thanks for signing up! This is the start of an exciting journey and you’re just one step away from completing your account setup to start using + your profile. +
+
Click the button below to verify your account and get started. +
+
+ + Verify email address + +


+
+
+
+ Need help? + Contact our support team +

+

Your Company | Kota Damansara, 47810 Petaling Jaya, Selangor, Malaysia
+
+
+
+
+
+
+
+