1
0
Fork 0

rfq: simplify, set email sender

This commit is contained in:
Sebastien Bourdeauducq 2020-04-15 21:17:19 +08:00
parent 7d0abf4b17
commit 103056cbe8
1 changed files with 10 additions and 24 deletions

View File

@ -23,7 +23,8 @@ app.config.update(
MAIL_DEBUG=False, MAIL_DEBUG=False,
MAIL_USERNAME=getenv("FLASK_MAIL_USERNAME"), MAIL_USERNAME=getenv("FLASK_MAIL_USERNAME"),
MAIL_PASSWORD=getenv("FLASK_MAIL_PASSWORD"), MAIL_PASSWORD=getenv("FLASK_MAIL_PASSWORD"),
MAIL_RECIPIENT=getenv("FLASK_MAIL_RECIPIENT") MAIL_RECIPIENT=getenv("FLASK_MAIL_RECIPIENT"),
MAIL_SENDER=getenv("FLASK_MAIL_SENDER")
) )
app.wsgi_app = ProxyFix(app.wsgi_app) app.wsgi_app = ProxyFix(app.wsgi_app)
@ -50,40 +51,25 @@ def send_rfq():
resp = jsonify(error="missing email") resp = jsonify(error="missing email")
return make_response(resp, 400) return make_response(resp, 400)
if "body" not in payload: if "note" not in payload:
resp = jsonify(error="missing body") resp = jsonify(error="missing note")
return make_response(resp, 400) return make_response(resp, 400)
if "configuration" not in payload: if "configuration" not in payload:
resp = jsonify(error="missing configuration") resp = jsonify(error="missing configuration")
return make_response(resp, 400) return make_response(resp, 400)
sender = current_app.config["MAIL_SENDER"]
recipient = current_app.config["MAIL_RECIPIENT"] recipient = current_app.config["MAIL_RECIPIENT"]
msg = Message( msg = Message(
"[ORDER HARDWARE - RFQ from %s]" % payload['email'], "RFQ for Sinara hardware from {}".format(payload["email"]),
reply_to=recipient, sender=sender,
sender=payload["email"], recipients=[recipient, payload["email"]])
recipients=[recipient]) msg.body = ("From: {}\nConfiguration: {}\nNote: {}"
msg.body = payload["body"] .format(payload["email"], payload["configuration"], payload["note"]))
msg.html = payload["body"]
msg_client_confirmation = Message(
"[M-Labs - Order Hardware]",
reply_to=recipient,
sender=recipient,
recipients=[payload["email"]])
msg_client_confirmation.body = "Hello! We've received your request and " \
"will be in contact soon. " \
"Here is a reminder of your configuration: {}" \
"Thank you!".format(payload["configuration"])
msg_client_confirmation.html = "Hello!<br />" \
"We've received your request and will be in contact soon.<br />" \
"Here is a reminder of your configuration: {}<br /><br />" \
"Thank you!".format(payload["configuration"])
with mail.connect() as conn: with mail.connect() as conn:
conn.send(msg) conn.send(msg)
conn.send(msg_client_confirmation)
return jsonify("ok") return jsonify("ok")