2022-09-17 18:12:14 +00:00
|
|
|
import requests
|
|
|
|
|
2022-10-05 15:54:29 +00:00
|
|
|
from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
|
2022-09-17 18:12:14 +00:00
|
|
|
|
2022-10-05 15:54:29 +00:00
|
|
|
api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
|
|
|
|
noreply = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
|
|
|
|
|
|
|
|
async def send_auth_email(user, token):
|
|
|
|
try:
|
2022-10-20 22:05:37 +00:00
|
|
|
to = "%s <%s>" % (user.name, user.email)
|
|
|
|
# TODO: i18n
|
|
|
|
subject = "Confirm email"
|
|
|
|
template = "email_confirmation_ru"
|
|
|
|
|
2022-10-05 15:54:29 +00:00
|
|
|
response = requests.post(
|
|
|
|
api_url,
|
|
|
|
auth=("api", MAILGUN_API_KEY),
|
2022-10-20 22:05:37 +00:00
|
|
|
data={"from": noreply,
|
|
|
|
"to": to,
|
|
|
|
"subject": subject,
|
|
|
|
"template": template,
|
|
|
|
"h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token}
|
2022-10-05 15:54:29 +00:00
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|