forked from M-Labs/web2019
37 lines
891 B
Python
37 lines
891 B
Python
from flask import current_app
|
|
from flask import json
|
|
from flask import jsonify
|
|
from flask import make_response
|
|
from flask import request
|
|
from flask_mail import Message
|
|
from app.api import bp
|
|
from app import mail
|
|
|
|
|
|
@bp.route("/rfq", methods=["POST"])
|
|
def send_rfq():
|
|
payload = request.json
|
|
payload = json.loads(json.htmlsafe_dumps(payload))
|
|
|
|
if "email" not in payload:
|
|
resp = jsonify(error="missing email")
|
|
return make_response(resp, 400)
|
|
|
|
if "body" not in payload:
|
|
resp = jsonify(error="missing body")
|
|
return make_response(resp, 400)
|
|
|
|
recipient = current_app.config["MAIL_RECIPIENT"]
|
|
|
|
msg = Message(
|
|
"[ORDER HARDWARE - RFQ from %s]" % payload['email'],
|
|
sender=payload["email"],
|
|
recipients=[recipient])
|
|
|
|
msg.body = payload["body"]
|
|
msg.html = payload["body"]
|
|
|
|
mail.send(msg)
|
|
|
|
return jsonify("ok")
|