File size: 2,900 Bytes
7824793
 
 
 
 
 
 
 
 
 
 
 
 
 
b738a7b
 
 
 
 
7824793
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0bd39bc
 
 
 
 
 
 
 
 
 
7824793
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
from flask import Flask, request, jsonify
from flask_cors import CORS
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from dotenv import load_dotenv

load_dotenv()

app = Flask(__name__)
# Allow CORS for the frontend domain (or all domains if specified)
CORS(app)

# Hardcoded configuration (Be extremely careful not to push your password to a public repository!)
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
SMTP_EMAIL = 'bhuvispartiate@gmail.com'
SMTP_PASSWORD = 'agyh veeo dvgv nysa' # Replace this with your actual Google App Password

def send_confirmation_email(to_email, name, college, pass_link):
    if not SMTP_EMAIL or not SMTP_PASSWORD:
        raise Exception("SMTP credentials are not configured on the server.")

    # Read the HTML template
    template_path = os.path.join(os.path.dirname(__file__), 'email_template.html')
    with open(template_path, 'r', encoding='utf-8') as f:
        html_content = f.read()

    # Replace placeholders
    html_content = html_content.replace('{{NAME}}', name)
    html_content = html_content.replace('{{COLLEGE}}', college)
    html_content = html_content.replace('{{PASS_LINK}}', pass_link)

    # Set up the email message
    msg = MIMEMultipart('alternative')
    msg['Subject'] = "CyberPunk2026 - Registration Confirmed"
    msg['From'] = f"CyberPunk2026 <{SMTP_EMAIL}>"
    msg['To'] = to_email

    # Attach the HTML content
    part = MIMEText(html_content, 'html')
    msg.attach(part)

    # Send the email
    with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
        server.starttls()
        server.login(SMTP_EMAIL or '', SMTP_PASSWORD or '')
        server.send_message(msg)

@app.route('/send-confirmation', methods=['POST'])
def handle_send_confirmation():
    data = request.json
    if not data:
        return jsonify({"error": "No JSON payload provided"}), 400

    email = data.get('email')
    name = data.get('name')
    college = data.get('college')
    pass_link = data.get('passLink')

    if not all([email, name, college, pass_link]):
        return jsonify({"error": "Missing required fields: email, name, college, passLink"}), 400

    try:
        send_confirmation_email(email, name, college, pass_link)
        return jsonify({"success": True, "message": "Confirmation email sent successfully"}), 200
    except Exception as e:
        import traceback
        error_details = traceback.format_exc()
        print("====== EMAIL SEND ERROR ======")
        print(error_details)
        print("==============================")
        return jsonify({
            "error": "Failed to send email", 
            "details": str(e),
            "traceback": error_details
        }), 500

if __name__ == '__main__':
    # Hugging Face Spaces expose port 7860
    port = int(os.getenv('PORT', 7860))
    app.run(host='0.0.0.0', port=port, debug=False)