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_USERNAME=getenv("FLASK_MAIL_USERNAME"),
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)
@ -50,40 +51,25 @@ def send_rfq():
resp = jsonify(error="missing email")
return make_response(resp, 400)
if "body" not in payload:
resp = jsonify(error="missing body")
if "note" not in payload:
resp = jsonify(error="missing note")
return make_response(resp, 400)
if "configuration" not in payload:
resp = jsonify(error="missing configuration")
return make_response(resp, 400)
sender = current_app.config["MAIL_SENDER"]
recipient = current_app.config["MAIL_RECIPIENT"]
msg = Message(
"[ORDER HARDWARE - RFQ from %s]" % payload['email'],
reply_to=recipient,
sender=payload["email"],
recipients=[recipient])
msg.body = payload["body"]
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"])
"RFQ for Sinara hardware from {}".format(payload["email"]),
sender=sender,
recipients=[recipient, payload["email"]])
msg.body = ("From: {}\nConfiguration: {}\nNote: {}"
.format(payload["email"], payload["configuration"], payload["note"]))
with mail.connect() as conn:
conn.send(msg)
conn.send(msg_client_confirmation)
return jsonify("ok")