-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (47 loc) · 2.11 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
49
50
51
52
53
54
55
56
from flask import Flask, render_template, request, flash
from flask_wtf import FlaskForm, CSRFProtect
from flask_mail import Mail, Message
import secrets
from wtforms import StringField, TextAreaField, SubmitField
from wtforms.validators import DataRequired, Email
from wtforms.fields.html5 import EmailField
application = Flask(__name__)
application.config['SECRET_KEY'] = secrets.token_urlsafe(16)
csrf = CSRFProtect(application)
mail = Mail(application)
application.config['MAIL_SERVER'] = 'smtp.gmail.com'
application.config['MAIL_PORT'] = 465
MAIL_DEFAULT_SENDER = '[email protected]'
application.config['MAIL_USERNAME'] = '[email protected]'
application.config['MAIL_PASSWORD'] = '#9851CLFA58A0D8183629r'
application.config['MAIL_DEFAULT_SENDER'] = '[email protected]'
application.config['MAIL_USE_TLS'] = False
application.config['MAIL_USE_SSL'] = True
mail = Mail(application)
class ContactForm(FlaskForm):
name = StringField("Name", validators=[DataRequired()])
email = EmailField("Email", validators=[DataRequired(), Email()])
address = StringField("Address", validators=[DataRequired()])
number = StringField("Number", validators=[DataRequired()])
message = TextAreaField("Message", validators=[DataRequired()])
submit = SubmitField("Send")
@application.route('/', methods=['GET', 'POST'])
def index():
form = ContactForm()
if request.method == 'POST' and form.validate_on_submit():
name = request.form['name']
message = request.form['message']
email = request.form['email']
address = request.form['address']
number = request.form['number']
msg = Message('Frontline Query', recipients=['[email protected]','[email protected]','[email protected]'])
msg.body = ("Name:{0}\n"
"\nEmail:{1}"
"\n Number:{2}"
"\n Message:{3}".format(name, email, number, message, ))
mail.send(msg)
return render_template('index.html', success=True)
else:
return render_template('index.html', form=form)
if __name__ == '__main__':
application.run()