-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
38 lines (29 loc) · 1007 Bytes
/
tasks.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
import os
import requests
import jinja2
from dotenv import load_dotenv
load_dotenv()
domain = os.getenv("MAILGUN_DOMAIN")
template_loader = jinja2.FileSystemLoader("templates")
template_env = jinja2.Environment(loader=template_loader)
def render_template(template_filename, **context):
return template_env.get_template(template_filename).render(**context)
def send_simple_message(to, subject, body, html):
return requests.post(
f"https://api.mailgun.net/v3/{domain}/messages",
auth=("api", os.getenv("MAILGUN_API_KEY")),
data={
"from": f"Erick Kiminza <mailgun@{domain}>",
"to": [to],
"subject": subject,
"text": body,
"html": html,
},
)
def send_user_registration_email(email, username):
return send_simple_message(
email,
"Successfully signed up",
f"Hi {username}! You have successfully signed up to the Know-US states REST API.",
render_template("email/action.html", username=username)
),