This commit is contained in:
Igor Lobanov
2022-10-21 00:05:37 +02:00
parent 3ebe067dc6
commit d34260e336
3 changed files with 19 additions and 23 deletions

View File

@@ -4,26 +4,22 @@ from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
noreply = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
subject = "Confirm email"
tmplt = """<html><body>
Follow the <a href='%s'>link</a> to authorize
</body></html>
"""
async def send_auth_email(user, token):
try:
to = "%s <%s>" % (user.username, user.email)
url_with_token = "https://newapi.discours.io/confirm/" + token
to = "%s <%s>" % (user.name, user.email)
# TODO: i18n
subject = "Confirm email"
template = "email_confirmation_ru"
response = requests.post(
api_url,
auth=("api", MAILGUN_API_KEY),
data={
"from": noreply,
"to": to,
"subject": subject,
"html": tmplt % url_with_token,
},
data={"from": noreply,
"to": to,
"subject": subject,
"template": template,
"h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token}
)
response.raise_for_status()
except Exception as e: