import os from flask import current_app from flask_mail import Mail, Message import smtplib from email.mime.text import MIMEText class EmailSender: def __init__(self, app=None): self.mail = None if app is not None: self.init_app(app) def init_app(self, app): self.mail = Mail(app) def send_verification_email(self, to_email, token): verify_url = f"{current_app.config['FRONTEND_URL']}/auth/verify?token={token}" html_body = f'Click here to verify your account.' msg = Message( subject="Verify your account", recipients=[to_email], html=html_body, sender=current_app.config.get('MAIL_DEFAULT_SENDER', 'no-reply@reward-app.local') ) if self.mail: self.mail.send(msg) else: print(f"[EMAIL to {to_email}] Verification: {verify_url}") def send_reset_password_email(self, to_email, token): reset_url = f"{current_app.config['FRONTEND_URL']}/auth/reset-password?token={token}" html_body = f'Click here to reset your password.' msg = Message( subject="Reset your password", recipients=[to_email], html=html_body, sender=current_app.config.get('MAIL_DEFAULT_SENDER', 'no-reply@reward-app.local') ) if self.mail: self.mail.send(msg) else: print(f"[EMAIL to {to_email}] Reset password: {reset_url}") def send_pin_setup_email(self, to_email, code): html_body = f"""

Set up your Parent PIN

To set your Parent PIN, enter the following code in the app:

{code}

This code is valid for 10 minutes.

If you did not request this, you can ignore this email.


Reward App
""" msg = Message( subject="Set up your Parent PIN", recipients=[to_email], html=html_body, sender=current_app.config.get('MAIL_DEFAULT_SENDER', 'no-reply@reward-app.local') ) if self.mail: self.mail.send(msg) else: print(f"[EMAIL to {to_email}] Parent PIN setup code: {code}")