-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
75 lines (62 loc) · 1.81 KB
/
server.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
from flask import Flask, render_template,request,redirect
import csv
import smtplib
from email.message import EmailMessage
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/<string:page_name>')
def html_page(page_name):
return render_template(page_name+".html")
@app.route('/submit_form', methods=['POST', 'GET'])
def submit_form():
if request.method=="POST":
data=request.form.to_dict()
write_to_csv(data)
send_email(data)
return redirect('thankyou')
else:
return 'something went wrong'
def send_email(data):
sender=data['email']
title=data['title']
body=data['body']
email=EmailMessage()
email['from']=sender
email['to']='agahamsc@live.com'
email['subject']=title
email.set_content(sender+"\n"+body)
with smtplib.SMTP(host='smtp.gmail.com', port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login('agahamtest@gmail.com', 'mijntest123')
smtp.send_message(email)
print('sent')
def write_to_csv(data):
with open('database.csv',mode='a') as database:
email=data['email']
title=data['title']
body=data['body']
csv_writer=csv.writer(database, delimiter=",", quoting=csv.QUOTE_MINIMAL)
csv_writer.writerow([email,title,body])
'''
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/components')
def components():
return render_template('components.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/work')
def work():
return render_template('work.html')
@app.route('/works')
def works():
return render_template('works.html')
'''
if __name__ == '__main__':
app.run()