diff --git a/app/api/services/register.py b/app/api/services/register.py index 22db263..ab102eb 100644 --- a/app/api/services/register.py +++ b/app/api/services/register.py @@ -13,7 +13,9 @@ from app.api.helpers.response_helper import ResponseHelper from werkzeug.security import generate_password_hash, check_password_hash from app.api.schemas.register import RegisterSchema from flask_mail import Mail, Message - +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart import datetime @@ -106,35 +108,76 @@ class RegisterService(BaseService): def send_register_mail(signup_email, email_uid,last_row_id,firstname): - signup_data = {} - signup_data["id"] = last_row_id - signup_data["uid"] = email_uid - #'d8651e10-3279-4858-87da-b52936faa6f0' - jwt_part = jwt.encode( - {"user": signup_data, 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=3330)}, - RegisterService.JWT_SECRET_KEY, algorithm='HS256' - ) - panel_url = "www.me.com" - link_url= str(panel_url) + '/csignup/' + jwt_part - print(link_url) - #firstname ='Name001' - msg = Message( - 'verify your MERMS Account', - sender ='message@chiefsoft.com', - recipients = [signup_email,'ameye+merscopy@chiefsoft.com'] - ) - msg.body = f""" - Hello {firstname}, - You received this message for account verification + sender_email = "message@chiefsoft.com" + sender_password = 'may12002!' # Use an app-specific password if using Gmail + receiver_email = signup_email + subject = "Python Email Test" + body = "This is a test email sent from Python." - Follow the link:{link_url} - For any Support - Reach Out - """ + msg = MIMEMultipart() + msg['Subject'] = subject + msg['From'] = sender_email + msg['To'] = receiver_email + msg.attach(MIMEText(body, 'plain')) # or 'html' for HTML content + + try: + # For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL) + # For other providers, consult their documentation for SMTP server and port + server = smtplib.SMTP('smtp.gmail.com', 587) + server.starttls() # Enable TLS encryption + server.login(sender_email, sender_password) + server.sendmail(sender_email, receiver_email, msg.as_string()) + print("Email sent successfully!") + except Exception as e: + print(f"Error sending email: {e}") + finally: + server.quit() # Close the connection + + # + # signup_data = {} + # signup_data["id"] = last_row_id + # signup_data["uid"] = email_uid + # #'d8651e10-3279-4858-87da-b52936faa6f0' + # + # jwt_part = jwt.encode( + # {"user": signup_data, 'exp' : datetime.datetime.utcnow() + datetime.timedelta(minutes=3330)}, + # RegisterService.JWT_SECRET_KEY, algorithm='HS256' + # ) + # panel_url = "www.me.com" + # link_url= str(panel_url) + '/csignup/' + jwt_part + # print(link_url) + # #firstname ='Name001' + # msg = Message( + # 'verify your MERMS Account', + # sender ='message@chiefsoft.com', + # recipients = [signup_email,'ameye+merscopy@chiefsoft.com'] + # ) + # msg.body = f""" + # Hello {firstname}, + # You received this message for account verification + # + # Follow the link:{link_url} + # + # For any Support + # Reach Out + # """ + # + # mail.send(msg) + +# mail = Mail(app) # instantiate the mail class +# +# # configuration of mail +# app.config['MAIL_SERVER'] = 'smtp.gmail.com' +# app.config['MAIL_PORT'] = 465 +# # app.config['MAIL_PORT'] = 587 +# app.config['MAIL_USERNAME'] = 'message@chiefsoft.com' +# app.config['MAIL_PASSWORD'] = 'may12002!' +# app.config['MAIL_USE_TLS'] = False +# app.config['MAIL_USE_SSL'] = True +# mail = Mail(app) - mail.send(msg) # {