mail_builder.build_message(template_names, extra_context=None, force_multipart=False, **defaults)

Constructs a EmailMessage using the template to provide arguments.

  • template_names (sequence) – A list of template names to pass to select_template. If a single string is passed, it will be wrapped in a list
  • extra_context (dict) – Extra context to pass to the template blocks.
  • force_multipart (bool) – Ensure a EmailMultipartMessage is built, even when no hmtl content is provided.
  • defaults (varied) – All extra arguments will be passed to the EmailMessage

EmailMessage instance.

class mail_builder.views.EmailFormMixin

A mixin intended for FormView which renders and sends an email on form valid.


The value to pass as email_templates to build_message


(Default: True)

Passed to EmailMessage.send


(Default: {})

Arguments to pass when calling build_message

get_email_context(form, **kwargs)

Hook to build the context to be used when rendering email template blocks. The default implementation will return kwargs, after setting ‘form’ to the form’s cleaned_data, if it’s not set.

get_email_kwargs(form, **kwargs)

Builds the dict of keyword arguments to pass to build_message.

The default implementation updates kwargs from self.email_kwargs.


Calls self.get_email_context and self.get_email_kwargs, then builds a message using build_message. Then calls send(fail_silently=self.fail_silently) on the message. Finally calls the superclass’s form_valid method.