-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (40 loc) · 1.48 KB
/
app.py
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
from flask import Flask, render_template, request, redirect, url_for
from flask_mail import Mail, Message
from dotenv import load_dotenv
import os
load_dotenv()
app_passcode = os.getenv("APP_PASSCODE")
app = Flask(__name__, template_folder='.')
@app.route('/')
def index():
# TODO: fetch slot data from the backend and pass it to the template
return render_template('index.html')
@app.route('/coaching.html')
def coaching():
return render_template('coaching.html')
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = app_passcode
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
@app.route('/send_email', methods=['POST'])
def send_email():
try:
email = request.form['email']
name = request.form['name']
date = request.form['date']
timebox = request.form.get('timebox', default='not selected')
print(f"Email: {email}")
print(f"Name: {name}")
print(f"Date: {date}")
print(f"Timebox: {timebox}")
msg = Message('Lesson Request', sender='[email protected]', recipients=['[email protected]'])
msg.body = f"I am requesting a lesson in the {timebox} on the date {date}.\nHere is my name and email: {name}, {email}"
mail.send(msg)
return 'Email sent!'
except Exception as e:
return str(e)
if __name__ == '__main__':
app.run(debug=True)