-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyproject.py
71 lines (58 loc) · 1.76 KB
/
myproject.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
from flask import Flask,render_template,request
from smtplib import SMTP
import smtplib
from random import randint
from pymongo import MongoClient
app = Flask(__name__)
@app.route('/')
def ind():
return render_template('index.html')
@app.route('/form')
def form():
return render_template('form.html')
@app.route('/reg',methods = ['POST', 'GET'])
def reg():
fname = request.form['fname']
lname = request.form['lname']
mail = request.form['email']
phone=request.form['phone']
add1=request.form['add1']
add2= request.form['add2']
add3= request.form['add3']
gmail_user = "[email protected]"
gmail_pwd = "MaDhU8150937838"
FROM = '[email protected]'
TO = [mail] # must be a list
SUBJECT = "Food bank confirmation"
TEXT = "Thank you for helping and we will be contacting you soon"
# Prepare actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
# server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) # or port 465 doesn't seem to work!
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
# server.quit()
server.close()
print('successfully sent the mail')
except:
print("failed to send mail")
conn = MongoClient()
db = conn.donorData
collection = db.donor
emp_rec1 = {
"First_name": fname,
"Last_name": lname,
"Email": mail,
"ph_no":phone,
"add1":add1,
"add2":add2,
"add3":add3
}
rec_id1 = collection.insert_one(emp_rec1)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)