0

I have an email verification while registering, and the verify link must in the form of a hyperlink.

from django.core.mail import send_mail
from django.conf import settings

def send_email_verification_mail(email, first_name, verify_link, exp):
    html = """
    <a href="{link}">Click to verify</a>
    """
    html.format(link=verify_link)
    subject = 'Your accounts need to be verified'
    message = f'Hi {first_name.capitalize()},\n\nClick on the link to verify your 
    account \n 
    \n{html}\n \nThis link will expire in {exp}'
    email_from = settings.EMAIL_HOST_USER
    recipient_list = [email]
    send_mail(subject, message, email_from, recipient_list)
    return True

This is the what I'm getting

Nikhil V
  • 7
  • 2
  • 1
    Does this answer your question? [How to send html email with django with dynamic content in it?](https://stackoverflow.com/questions/3005080/how-to-send-html-email-with-django-with-dynamic-content-in-it) – Yevhen Kuzmovych Jun 02 '23 at 09:05

1 Answers1

0

str.format method returns the formatted string, it doesn't modify the original string. Try assigning the return value to your original string.

html = html.format(link=verify_link)

Documentation says that send_mail has html_message argument and,

If html_message is provided, the resulting email will be a multipart/alternative email with message as the text/plain content type and html_message as the text/html content type

So you can do as it is shown in this answer to modify your code:

Monata
  • 308
  • 1
  • 9