0

I'm able to send the email, however, the link does not show up. There is just a blank spot where the link is supposed to be. Do I need to add it to like the username?

from django.core.mail import EmailMessage
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context

subject, from_email = 'subject', '<info@mysite.com>'
plaintext = get_template('email.txt')
htmly = get_template('email.html')
username = user.username
d = { 'username': username }
text_content = plaintext.render(d)
html_content = htmly.render(d)            
msg = EmailMultiAlternatives(subject, text_content, from_email, [user.email])
msg.attach_alternative(html_content, "text/html")
msg.send()

Here is the email.html file:

<h3>Hi <strong>{{ username }}</strong>,</h6>
<p> disown kvdsvnsdov vknvisodvnsdv dsdov siod vsd. Here is a link:</p>
<a href="http://domain{% url 'home' %}">Check Now</a>

Here is the email.txt:

Hi {{ username }},
disown kvdsvnsdov vknvisodvnsdv dsdov siod vsd. Here is a link:
http://domain{% url 'home' %}
user10421193
  • 217
  • 2
  • 11
  • What does `text_content` & `html_content` gives you ? – Julien Kieffer Oct 12 '19 at 15:07
  • The problem is that Django emails render content as a string, rather than HTML. To have your html rendered, you have to do it this way. See this answer: https://stackoverflow.com/questions/2809547/creating-email-templates-with-django – user10421193 Oct 12 '19 at 15:14

0 Answers0