forked from Titogelo/yOUng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (31 loc) · 1.29 KB
/
main.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
"""`main` is the top level module for your Flask application."""
# Import the Flask Framework
from flask import Flask, render_template, request
from google.appengine.api import mail
import json
app = Flask(__name__)
# Note: We don't need to call run() since our application is embedded within
# the App Engine WSGI application server.
@app.route('/')
def home():
"""Return a friendly HTTP greeting."""
return render_template("index.html")
@app.errorhandler(404)
def page_not_found(e):
"""Return a custom 404 error."""
return 'Sorry, Nothing at this URL.', 404
@app.errorhandler(500)
def application_error(e):
"""Return a custom 500 error."""
return 'Sorry, unexpected error: {}'.format(e), 500
@app.route('/message', methods=['GET', 'POST'])
def sent_message():
email_from = request.form['email']
text = request.form['message']
subject = request.form['subject']
message = mail.EmailMessage(sender="[email protected]",
subject="FOO web contact")
message.to = ['[email protected]', '[email protected]']
message.body = "From: %s \nSubject: %s \nMessage: %s" % (email_from, subject, text)
message.send()
return json.dumps({'success': True}), 200, {'ContentType': 'application/json'}