django.core.mail.messages EmailMessage Example Code

The EmailMessage class is contained with the django.core.mail module within the Django project code base.

Example 1 from django-emailmessagetemplate

django-emailmessagetemplates is a code library that makes it easier to add functionality for end users to customize email templates in a Django application. The code is available under the BSD 3-Clause "New" or "Revised" License.

django-emailmessagetemplates / emailmessagetemplates /

import copy

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

from models import EmailMessageTemplate

def send_mail(name, related_object=None, context={}, from_email=None,
              recipient_list=[], fail_silently=False, auth_user=None,
               auth_password=None, connection=None):
    Easy wrapper for sending a single templated message to a recipient list.  
    The template to use is retrieved from the database based on the name and 
    related_object (optional) fields.
    All members of the recipient list will see the other recipients in the 'To' 
    If auth_user is None, the EMAIL_HOST_USER setting is used.
    If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.

    template = EmailMessageTemplate.objects.get_template(name, related_object)

    connection = connection or get_connection(username=auth_user,


    return template.send()

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via Twitter & Facebook.

Matt Makai 2012-2019