-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
35 lines (31 loc) · 860 Bytes
/
mail.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
from flask_mail import Mail, Message
from flask import Flask
from flask import request
app = Flask(__name__)
app.config.update(
# DEBUG=True,
#EMAIL SETTINGS
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME = 'email@gmail.com',
MAIL_PASSWORD = 'password'
)
mail = Mail(app)
@app.route('/send-mail',methods=[ 'POST'])
def send_mail():
print(request.method)
if request.method == 'POST':
r=request.json
print(str(r))
try:
msg = Message("Restaurant details!",
sender="email@gmail.com",
recipients=[str(r['email'])])
msg.body = str(r['restaurants'])
mail.send(msg)
return 'Mail sent!'
except Exception as e:
return(str(e))
if __name__ == '__main__':
app.run()