Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 792625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:01:18+00:00 2026-05-14T22:01:18+00:00

I want to send HTML-emails, using Django templates like this: <html> <body> hello <strong>{{username}}</strong>

  • 0

I want to send HTML-emails, using Django templates like this:

<html>
<body>
hello <strong>{{username}}</strong>
your account activated.
<img src="mysite.com/logo.gif" />
</body>

I can’t find anything about send_mail, and django-mailer only sends HTML templates, without dynamic data.

How do I use Django’s template engine to generate e-mails?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:01:19+00:00Added an answer on May 14, 2026 at 10:01 pm

    From the docs, to send HTML e-mail you want to use alternative content-types, like this:

    from django.core.mail import EmailMultiAlternatives
    
    subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
    text_content = 'This is an important message.'
    html_content = '<p>This is an <strong>important</strong> message.</p>'
    msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
    

    You’ll probably want two templates for your e-mail – a plain text one that looks something like this, stored in your templates directory under email.txt:

    Hello {{ username }} - your account is activated.
    

    and an HTMLy one, stored under email.html:

    Hello <strong>{{ username }}</strong> - your account is activated.
    

    You can then send an e-mail using both those templates by making use of get_template, like this:

    from django.core.mail import EmailMultiAlternatives
    from django.template.loader import get_template
    from django.template import Context
    
    plaintext = get_template('email.txt')
    htmly     = get_template('email.html')
    
    d = Context({ 'username': username })
    
    subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
    text_content = plaintext.render(d)
    html_content = htmly.render(d)
    msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
    msg.attach_alternative(html_content, "text/html")
    msg.send()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django templates to create an e-mail. I do something like this: msg_html
I'm using PHP to send html emails. I've tried to import css files inside
I want to send emails in HTML format. How can I use asp.net to
I'm using Rails to send emails and I just want to send a plain
I want to render an HTML-EMail and send it to our customers using some
I want to send a HTML file as message body and want to attach
For testing purposes I want send mail to my localhost user account rather than
I am using this code to send email var message = new MailMessage(abc@somedomain.com, administrator@anotherdomain.com);
I want to send emails where the data is from a php/mySQL query. I
I want so send every week an update by email. But Im afraid that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.