#wrprqrkahnxqgjma import smtplib from email.message import EmailMessage def mail_resetpass(receiverlist, temppass): global success email_address = "evisionmalaysia@gmail.com" email_password = "wrprqrkahnxqgjma" contacts = receiverlist success = False content = "Hi,\n\nYour password had been successfully reset. You may use the following generated temporary password to login.\n\nTemporary Password: {}\n\nHave a good day,\ne-Vision Support Team\n\nThis email was generated by computer. Please do not reply.".format(temppass) msg = EmailMessage() msg['Subject'] = "Reset Password" msg['From'] = email_address msg['To'] = ', '.join(contacts) msg.set_content(content, subtype="plain", charset='us-ascii') with smtplib.SMTP('smtp.gmail.com', 587) as smtp: smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(email_address, email_password) try: smtp.send_message(msg) success = True except smtplib.SMTPException: success = False print("Error: an error occured in SMTP server. Failed to send email") return success def mail_newuserregister(receiverlist, temppass): global success email_address = "evisionmalaysia@gmail.com" email_password = "wrprqrkahnxqgjma" contacts = receiverlist success = False content = "Hi,\n\nWelcome to e-Vision. An account had been successfully created by company's Admin for you. Please use the following details to login to the system.\n\nEmail Address: {}\nTemporary Password: {}\n\nHave a good day,\ne-Vision Support Team\n\nThis email was generated by computer. Please do not reply.".format(contacts[0], temppass) msg = EmailMessage() msg['Subject'] = "e-Vision Account Created" msg['From'] = email_address msg['To'] = ', '.join(contacts) msg.set_content(content, subtype="plain", charset='us-ascii') with smtplib.SMTP('smtp.gmail.com', 587) as smtp: smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(email_address, email_password) try: smtp.send_message(msg) success = True except smtplib.SMTPException: success = False print("Error: an error occured in SMTP server. Failed to send email") return success def mail_accidetected(receiverlist, cam_id, street, city, state, datetime, aid): global success email_address = "evisionmalaysia@gmail.com" email_password = "wrprqrkahnxqgjma" contacts = receiverlist success = False content = "Hi,\n\nAn accident had been detected in the area info provided in below.\n\nCamera ID: {}\nStreet Name: {}\nCity: {}\nState: {}\nAccident Date Time: {}\n\nPlease immediately review the accident through e-Vision system to provide necessary support!\n\nHave a good day,\ne-Vision Support Team\n\nThis email was generated by computer. Please do not reply.".format(cam_id, street, city, state, datetime) msg = EmailMessage() msg['Subject'] = "e-Vision Accident Detected Notification" msg['From'] = email_address msg['To'] = ', '.join(contacts) msg.set_content('This is an email') msg.add_alternative("""\ <!DOCTYPE html> <html> <body> <p>Hi,</p> <p>An accident had been detected in the area info provided in below.</p> <p>Camera ID: {} <br>Street Name: {} <br>City: {} <br>State: {} <br>Accident Date Time: {}</p> <p>Please immediately review the accident through e-Vision system to provide necessary support!<br>Or click on below to perform remote review through mobile web.</p> <a href="https://evision-remote-review.herokuapp.com/web_accident_review.php?aid={}"><button type="button">Review Now</button></a> <p>Have a good day,<br>e-Vision Support Team</p> <p>This email was generated by computer. Please do not reply.</p> </body> </html> """.format(cam_id, street, city, state, datetime, aid), subtype='html') with smtplib.SMTP('smtp.gmail.com', 587) as smtp: smtp.ehlo() smtp.starttls() smtp.ehlo() smtp.login(email_address, email_password) try: smtp.send_message(msg) success = True except smtplib.SMTPException: success = False print("Error: an error occured in SMTP server. Failed to send email") return success