cdh.core.mail.utils module
- cdh.core.mail.utils.send_mass_personalised_custom_mail(datatuple: List[Tuple[str, dict, List[str]]], email_class, template_context: dict, contents: str, sender: Optional[str] = None, banner: Optional[str] = None, footer: Optional[str] = None, from_email: str = None, plain_context: dict = None, html_context: dict = None, language: str = 'nl') int [source]
Given a datatuple of (subject, personal_context, recipient_list), send each message to each recipient list.
This method takes advantage of
BaseCustomTemplateEmail
caching to make sure the custom templates are only built once, speeding up rendering.personal_context and template_context will be merged together to create a personalised email.
html_context and plain_context can be used to override something in the regular template_context for either the html version of the plain text version. (Note: you can also add a key that does not exist in template_context)
- Parameters
datatuple (tuple[str, dict, list[str]]) – A tuple of tuples: (subject, personal_context, recipient_list)
from_email (str) – the FROM: value. Uses settings.FROM_EMAIL if omitted
email_class (extension of
BaseCustomTemplateEmail
) – the custom email class to usecontents (str) – the template code for the contents block
sender (str or None) – the template code for the sender block
banner (str or None) – the template code for the banner block
footer (str or None) – the template code for the footer block
template_context (dict) – any context data needed for rendering the templates
html_context (dict) – additional context data for the HTML template
plain_context (dict) – additional context data for the plain template
language (str) – the langauge code used during rendering
- Returns
the number of emails send
- Return type
- cdh.core.mail.utils.send_mass_personalised_mass_mail(datatuple: List[Tuple[str, dict, List[str]]], template_context: dict, html_template: Optional[str] = None, plain_template: Optional[str] = None, from_email: str = None, plain_context: dict = None, html_context: dict = None, language: str = 'nl') int [source]
Given a datatuple of (subject, personal_context, recipient_list), send each message to each recipient list.
personal_context and template_context will be merged together to create a personalised email.
html_context and plain_context can be used to override something in the regular template_context for either the html version of the plain text version. (Note: you can also add a key that does not exist in template_context)
- Parameters
datatuple (tuple[str, dict, list[str]]) – A tuple of tuples: (subject, personal_context, recipient_list)
from_email (str) – the FROM: value. Uses settings.FROM_EMAIL if omitted
html_template (str) – the HTML template to render
plain_template (str) – the plain template to render
template_context (dict) – any context data needed for rendering the templates
html_context (dict) – additional context data for the HTML template
plain_context (dict) – additional context data for the plain template
language (str) – the langauge code used during rendering
- Returns
the number of emails send
- Return type
- Raises
ValueError – if no template at all was supplied
- cdh.core.mail.utils.send_template_email(recipient_list: List[str], subject: str, template_context: dict, html_template: Optional[str] = None, plain_template: Optional[str] = None, from_email: Optional[str] = None, plain_context: Optional[dict] = None, html_context: Optional[dict] = None, language: str = 'nl') int [source]
Light wrapper for
TemplateEmail
.You need to provide at least one of the template variants (HTML or plain). Or both, if you want.
- Parameters
recipient_list (list of str) – list of recipients
subject (str) – Email subject
from_email (str) – the FROM: value. Uses settings.FROM_EMAIL if omitted
html_template (str) – the HTML template to render
plain_template (str) – the plain template to render
template_context (dict) – any context data needed for rendering the templates
html_context (dict) – additional context data for the HTML template
plain_context (dict) – additional context data for the plain template
language (str) – the langauge code used during rendering
- Returns
the number of emails send
- Return type
- Raises
ValueError – if no template at all was supplied