From 63f4f987a96363ea9de8e1e6e65e817d15d8fa2a Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 4 Jul 2022 14:56:14 +0530 Subject: [PATCH] feat: verification link email template with polished email body --- .../accounts/emails/verification-link.txt | 9 +++++++++ accounts/utils.py | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 accounts/templates/accounts/emails/verification-link.txt diff --git a/accounts/templates/accounts/emails/verification-link.txt b/accounts/templates/accounts/emails/verification-link.txt new file mode 100644 index 0000000..f52a9a2 --- /dev/null +++ b/accounts/templates/accounts/emails/verification-link.txt @@ -0,0 +1,9 @@ +Hello {{ username }}, + +Please click on the link below to verify your email. +{{ link }} + +If you don't recognise this activity, please delete this mail. + +Cheers, +Hostea team diff --git a/accounts/utils.py b/accounts/utils.py index e8edb27..66717ed 100644 --- a/accounts/utils.py +++ b/accounts/utils.py @@ -17,6 +17,7 @@ from datetime import datetime, timezone from django.utils.crypto import get_random_string from django.core.mail import send_mail from django.shortcuts import redirect +from django.template.loader import render_to_string from django.urls import reverse from django.utils.http import urlencode from django.conf import settings @@ -34,12 +35,24 @@ def send_verification_email(request, challenge): f"{request.scheme}://{request.get_host()}{challenge.verification_link()}" ) + ctx = { + "link": verification_link, + "username": challenge.owned_by.username, + } + + body = render_to_string( + "accounts/emails/verification-link.txt", + context=ctx, + ) + email = challenge.owned_by.email + sender = settings.HOSTEA["EMAIL_SENDER_ADDRESS"] + send_mail( subject="[Hostea] Please confirm your email address", - message=f"Please confirm your email address {email}.\n {verification_link}", - from_email="No reply Hostea", # TODO read from settings.py + message=body, + from_email=f"No reply Hostea<{sender}>", # TODO read from settings.py recipient_list=[email], )