Implement email sending
This commit is contained in:
parent
f6fb0cb00a
commit
f5f74540fd
4 changed files with 22 additions and 9 deletions
|
@ -2,10 +2,12 @@ import datetime
|
|||
import json
|
||||
import random
|
||||
import re
|
||||
import requests
|
||||
import string
|
||||
import traceback
|
||||
import unicodedata
|
||||
|
||||
from flask import current_app as app
|
||||
from functools import wraps
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
|
@ -34,3 +36,13 @@ def flat_multi(multidict):
|
|||
value = values[0] if type(values) == list and len(values) == 1 else values
|
||||
flat[key] = value.encode("utf-8")
|
||||
return flat
|
||||
|
||||
def send_email(recipient, subject, body):
|
||||
api_key = app.config["MG_API_KEY"]
|
||||
data = {"from": "EasyCTF Administrator <%s>" % (app.config["ADMIN_EMAIL"]),
|
||||
"to": recipient,
|
||||
"subject": subject,
|
||||
"text": body
|
||||
}
|
||||
auth = ("api", api_key)
|
||||
return requests.post("https://api.mailgun.net/v3/%s/messages" % (app.config["MG_HOST"]), auth=auth, data=data)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from argparse import ArgumentParser
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
import api
|
||||
import config
|
||||
import json
|
||||
|
@ -8,11 +10,7 @@ import os
|
|||
|
||||
from api.decorators import api_wrapper
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
||||
app.config["UPLOAD_FOLDER"] = config.UPLOAD_FOLDER
|
||||
app.config.from_object(config)
|
||||
|
||||
if not os.path.exists(app.config["UPLOAD_FOLDER"]):
|
||||
os.makedirs(app.config["UPLOAD_FOLDER"])
|
||||
|
|
|
@ -19,3 +19,6 @@ UPLOAD_FOLDER = os.path.normpath("../web/files")
|
|||
|
||||
CTF_BEGIN = 0 # To be used later
|
||||
CTF_END = 0 # To be used later
|
||||
MG_HOST = ""
|
||||
MG_API_KEY = ""
|
||||
ADMIN_EMAIL = ""
|
||||
|
|
Loading…
Reference in a new issue