This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
66 lines (51 loc) · 1.9 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from flask import Flask, request
from flask_cors import CORS
from envelopes import Envelope
from discord_webhook import DiscordWebhook
import toml, os, sys
if not os.path.exists("settings.toml"):
print(
"No config file found. Perhaps you need to rename 'ex_settings.toml' and edit it?"
)
sys.exit(1)
settings = toml.loads(open("settings.toml").read())
email_settings = settings["email"]
print(email_settings)
discord_settings = settings["discord"]
print(discord_settings)
app = Flask(__name__)
CORS(app)
@app.route("/", methods=["GET", "POST"])
def main():
if request.method == "POST":
name = request.json["name"]
email = request.json["email"]
msg = request.json["message"]
print(name + "<" + email + "> said: " + msg)
if email_settings["enabled"]:
for to_addr in email_settings["to"]:
envelope = Envelope(
from_addr=(email_settings["from"], email_settings["my_name"]),
to_addr=(to_addr, "Recipient"),
subject="Form submission by " + name,
text_body="From '" + email + "': \n'" + msg + "'\n- " + name,
)
envelope.send(
email_settings["server"],
login=email_settings["from"],
password=email_settings["password"],
tls=email_settings["tls"],
)
print("Sent a copy to " + to_addr)
if discord_settings["enabled"]:
webhook = DiscordWebhook(
url=discord_settings["url"],
content="From `" + email + "`: \n`" + msg + "`\n- `" + name + "`",
)
webhook.execute()
print("Sent a copy to discord webhook")
return "Handled."
else:
return "Error."
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9090, debug=True)