-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (28 loc) · 1010 Bytes
/
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
import os
import sendgrid
from flask import Flask, request, redirect, abort
app = Flask(__name__)
sendgrid_client = sendgrid.SendGridClient(os.environ['SENDGRID_USERNAME'], os.environ['SENDGRID_PASSWORD'])
@app.route('/')
def index():
return redirect(os.environ['USER_SITE'])
@app.route('/send', methods=['POST'])
def forward():
email_subject = 'Message from ' + request.form['name'] + ' about ' + request.form['subject']
email_to = os.environ['USER_EMAIL']
email_from = request.form['email']
email_txt = request.form['message']
#
message = sendgrid.Mail()
message.add_to(email_to)
message.set_subject(email_subject)
message.set_html(email_txt)
message.set_text(email_txt)
message.set_from(email_from)
status, msg = sendgrid_client.send(message)
if status != 200:
abort(500)
return redirect(os.environ['SUCCESS_PAGE'])
@app.errorhandler(500)
def error(e):
return ('Sorry, something went wrong! %s - %s' % (e.__class__, e), 500)