#17193: Send templated email.
-----------------------------+-------------------------------------------
     Reporter:  tomchristie  |                    Owner:  julianapplebaum
         Type:  New feature  |                   Status:  new
    Component:  Core (Mail)  |                  Version:
     Severity:  Normal       |               Resolution:
     Keywords:               |             Triage Stage:  Accepted
    Has patch:  1            |      Needs documentation:  1
  Needs tests:  1            |  Patch needs improvement:  1
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+-------------------------------------------
Description changed by timgraham:

Old description:

> If your sending email it's likely that you want to render the body text
> from template, but there's currently no shortcut to send an email based
> on a template.
>
> The attached patch is based on a stripped down version of
> https://github.com/bradwhittington/django-templated-email
>
> It adds `django.shortcuts.send_templated_mail`, which mirrors the
> existing `send_mail`, but which renders the subject and body of the mail
> from a template, rather than taking their values explicitly.  It also
> supports multipart html/plaintext emails.
>
> The docs will look something like this...
>
>   **send_templated_mail(template_name, from_email, recipient_list,
> dictionary=None, context_instance=None, fail_silently=False,
> auth_user=None, auth_password=None, connection=None):**
>     Sends a mail, rendering the subject and body of the email from a
> template.
>
>     The template should contain a block named 'subject', and either/both
> of a 'plain' and/or 'html' block.
>
>     If only the 'plain' block exists, a plaintext email will be sent.
>
>     If only the 'html' block exists, the plaintext component will be
> automatically generated from the html, and a multipart email will be
> sent.
>
>     If both the 'plain' and 'html' blocks exist, a multipart email will
> be sent.
>
>     **Required arguments:**
>
>     `template_name` - The template that should be used to render the
> email.
>
>     `from_email` - The sender's email address.
>
>     `recipient_list` - A list of reciepient's email addresses.
>
>     **Optional arguments:**
>
>     `dictionary` - The context dictionary used to render the template. By
> default, this is an empty dictionary.
>
>     `context_instance` - The Context instance used to render the
> template. By default, the template will be rendered with a Context
> instance (filled with values from dictionary).
>
>     `fail_silently` - As in `send_mail`.
>
>     `auth_user`     - As in `send_mail`.
>
>     `auth_password` - As in `send_mail`.
>
>     `connection`    - As in `send_mail`.

New description:

 If your sending email it's likely that you want to render the body text
 from template, but there's currently no shortcut to send an email based on
 a template.

 The attached patch is based on a stripped down version of
 https://github.com/bradwhittington/django-templated-email

 It adds `django.shortcuts.send_templated_mail`, which mirrors the existing
 `send_mail`, but which renders the subject and body of the mail from a
 template, rather than taking their values explicitly.  It also supports
 multipart html/plaintext emails.

 The docs will look something like this...
 {{{
   **send_templated_mail(template_name, from_email, recipient_list,
 dictionary=None, context_instance=None, fail_silently=False,
 auth_user=None, auth_password=None, connection=None):**
     Sends a mail, rendering the subject and body of the email from a
 template.

     The template should contain a block named 'subject', and either/both
 of a 'plain' and/or 'html' block.

     If only the 'plain' block exists, a plaintext email will be sent.

     If only the 'html' block exists, the plaintext component will be
 automatically generated from the html, and a multipart email will be sent.

     If both the 'plain' and 'html' blocks exist, a multipart email will be
 sent.

     **Required arguments:**

     `template_name` - The template that should be used to render the
 email.

     `from_email` - The sender's email address.

     `recipient_list` - A list of reciepient's email addresses.

     **Optional arguments:**

     `dictionary` - The context dictionary used to render the template. By
 default, this is an empty dictionary.

     `context_instance` - The Context instance used to render the template.
 By default, the template will be rendered with a Context instance (filled
 with values from dictionary).

     `fail_silently` - As in `send_mail`.

     `auth_user`     - As in `send_mail`.

     `auth_password` - As in `send_mail`.

     `connection`    - As in `send_mail`.
 }}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/17193#comment:31>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.c41cde6a8214dfb51e84a2a1d61afcee%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to