def admin_failed_login_email(): form = LoginForm() response = requests.get('https://ipinfo.io/') data = response.json() city = data['city'] state = data['region'] country = data['country'] if country == "US": country = "United States of America" ts = calendar.timegm(time.gmtime()) timestamp = time.ctime(ts) powelltech_email = '*****@*****.**' customer_email = form.email.data text = "" msg = MIMEMultipart('alternative') msg['Subject'] = f'''Unsuccessful AdminAccess Login.''' msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('admin_failed_login_email.html', city=city, state=state, country=country, timestamp=timestamp) part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def admin_logout_email(): powelltech_email = '*****@*****.**' admin_email = current_user.email text = f"{current_user.first_name} has been logged out." msg = MIMEMultipart('alternative') msg['Subject'] = f'''Successful logout for {current_user.first_name} {current_user.last_name}''' msg['From'] = "PowellTech Inc. ©" msg['To'] = admin_email html = render_template('admin_logout_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, admin_email, msg.as_string()) mail.quit()
def update_account_information_email(update_account_information_email): form = UpdateAccountForm() powelltech_email = '*****@*****.**' customer_email = current_user.email text = '' msg = MIMEMultipart('alternative') msg['Subject'] = f'''Account information changed for {form.first_name.data}''' msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('update_account_information_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_repair_email(repair): form = RepairForm() powelltech_email = '*****@*****.**' customer_email = current_user.email text = "" msg = MIMEMultipart('alternative') msg['Subject'] = f'''Repair request received for {form.first_name.data}''' msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('repair_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_register_email(user): form = RegistrationForm() powelltech_email = '*****@*****.**' customer_email = form.email.data msg = MIMEMultipart('alternative') text = '' msg['Subject'] = "Welcome to PowellTech, " + form.first_name.data + "!" msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('register_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_invoice_email(): form = InvoiceForm() powelltech_email = "*****@*****.**" customer_email = form.email.data msg = MIMEMultipart('alternative') text = '' msg['Subject'] = "Invoice: " + form.first_name.data + ' ' + form.last_name.data + " (" + form.order_number.data + ")" msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('invoice_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_admin_user_registration_email(user): form = AdminRegistrationForm() powelltech_email = "*****@*****.**" customer_email = form.email.data msg = MIMEMultipart('alternative') text = '' msg['Subject'] = "Admin Access Granted" msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('admin_user_registration_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_reset_email(user): token = user.get_reset_token() form = RequestResetForm() powelltech_email = '*****@*****.**' customer_email = form.email.data text = "" msg = MIMEMultipart('alternative') msg['Subject'] = f'''Password Reset for {form.email.data}''' msg['From'] = "PowellTech Inc. ©" msg['To'] = customer_email html = render_template('reset_email.html') part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()
def send_system_status_failure_email(): powelltech_email = "*****@*****.**" customer_email = "*****@*****.**" msg = MIMEMultipart('alternative') text = '' msg['Subject'] = "Fatal Alert | Systems Offline" msg['From'] = "PowellTech Inc. © Engineering" msg['To'] = customer_email html = ''' <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet" /> </head> <body> <header> <h1 style="text-align:center;font-family:Gothic A1,sans-serif;font-weight:100;" > <img src="https://i.ibb.co/bd26Cym/Small-Logo.jpg" alt="Small-Logo" style="max-width:25%; border:0" /> <br /> (Internal - Distribution Strictly Prohibited) </h1> <div style="margin-left:5%;margin-right:5%;font-family:Gothic A1,sans-serif;font-weight:100;" > <h1 style="text-align:center;font-family:Gothic A1,sans-serif;font-weight:100;" > System Status: </h1> <h2 style="text-align:center;font-family:Gothic A1,sans-serif;font-weight:100;" > Systems <span style="color:red">OFFLINE</span> </h2> <hr /> <h3 style="text-align:center;font-family:Gothic A1,sans-serif; font-weight: 100" > Attention: PowellTech Vital Systems are currently: <span style="color:red">OFFLINE</span> <br /> <br /> Upon completion of a Systems Check, a PowellTech systems failure has been detected, and unresolved. <br /> Vital systems are non-operational. <br /> A system check will be attempted again in 5 minutes. </h3> <hr /> <h6 style="text-align:center;font-family:Gothic A1,sans-serif;font-weight:100;" > <img src="https://i.ibb.co/bd26Cym/Small-Logo.jpg" alt="Small-Logo" style="width:10%; border:0" /> </h6> <p style="text-align:center;"> Copyright © 2019 Powell Industries </p> <p style="text-align:center;"> All Rights Reserved. </p> </div> </header> </body> </html> ''' part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') msg.attach(part1) msg.attach(part2) mail = smtplib.SMTP_SSL('smtp.gmail.com', 465) mail.ehlo() mail.login(powelltech_email, 'Powell2019!') mail.sendmail(powelltech_email, customer_email, msg.as_string()) mail.quit()