steambird/mail/mailsender.py
def create_multilingual_mail(template_name: str, subject: str, context: dict,
                             **kwargs) -> EmailMessage:
    """
    Creates an instance of EmailMessage. If multiple languages exist for
    the given template name, it will create an RFC8255_ compatible email, and if
    only one language exists, it will simply send an email in that language,
    without bothering with any multilingual crap.

    As of implementing this method, very few to no email clients support
    RFC8255_ and so it is recommended to either use create_mail with a
    preference language or use this method and only create one set of language
    templates.

    :param template_name: The template that should be used for this email
    :param subject: The subject of this email
    :param context: The context for the template
    :param kwargs: Any other data that should be passed to the EmailMessage
        constructor
    :return: an EmailMessage

    .. _RFC8255: https://tools.ietf.org/html/rfc8255
    """
    _ensure_setup()
    kwargs['headers'] = kwargs['headers'] if 'headers' in kwargs else {}

    kwargs['headers'] = {"X-Mailer": get_mailer_name(), **kwargs['headers']}

    langs = templates[template_name]

    if len(langs.items()) == 1:
        lang, tpls = list(langs.items())[0]

        with language(lang):
            kwargs['headers'] = {"Content-Language": lang, **kwargs['headers']}

            msg = MultiTemplatableEmailMessage(
                subject=subject,
                body=False,
                **kwargs
            )

            for template in tpls:
                msg.attach_alternative(
                    SafeMIMEText(
                        _text=get_template(template['file']).render({
                            'locale': template['locale'],
                            **context,
                        }),
                        _subtype=template['subtype'],
                        _charset=msg.encoding or settings.DEFAULT_CHARSET
                    ), 'unknown/unknown')

        return msg

    msg = MultilingualEmailMessage(subject=subject, **kwargs)

    for lang, tpls in langs.items():
        with language(lang):
            lang_alt = MIMEMultipart(_subtype='alternative')
            lang_alt.add_header("Subject", _(subject))

            for template in tpls:
                lang_alt.attach(
                    SafeMIMEText(get_template(template['file']).render({
                        'locale': template['locale'],
                        **context,
                    }), _subtype=template['subtype']))

            msg.add_language(lang, lang_alt)

    info = MIMEMultipart(_subtype='alternative')
    info.attach(SafeMIMEText(
        get_template("steambird/../templates/mail/multilingual_header.html").render({}),
        _subtype="html", _charset="utf-8"))
    info.attach(SafeMIMEText(
        get_template("steambird/../templates/mail/multilingual_header.plain").render({}),
        _subtype="plain", _charset="utf-8"))

    info.add_header("Content-Disposition", "inline")

    msg.attach(info)

    return msg

    Creates an instance of EmailMessage. If multiple languages exist for
    the given template name, it will create an RFC8255_ compatible email, and if
    only one language exists, it will simply send an email in that language,
    without bothering with any multilingual crap.

    As of implementing this method, very few to no email clients support
    RFC8255_ and so it is recommended to either use create_mail with a
    preference language or use this method and only create one set of language
    templates.

    :param template_name: The template that should be used for this email
    :param subject: The subject of this email
    :param context: The context for the template
    :param kwargs: Any other data that should be passed to the EmailMessage
        constructor
    :return: an EmailMessage

    .. _RFC8255: https://tools.ietf.org/html/rfc8255
    
Creates an instance of EmailMessage. If multiple languages exist for
the given template name, it will create an RFC8255_ compatible email, and if
only one language exists, it will simply send an email in that language,
without bothering with any multilingual crap.

As of implementing this method, very few to no email clients support
RFC8255_ and so it is recommended to either use create_mail with a
preference language or use this method and only create one set of language
templates.
Creates an instance of EmailMessage . If multiple languages exist for the given template name it will create an RFC8255_ compatible email and if only one language exists it will simply send an email in that language without bothering with any multilingual crap . As of implementing this method very few to no email clients support RFC8255_ and so it is recommended to either use create_mail with a preference language or use this method and only create one set of language templates .
def create_multilingual_mail(template_name: str, subject: str, context: dict,
                             **kwargs) -> EmailMessage:
    _ensure_setup()
    kwargs['headers'] = kwargs['headers'] if 'headers' in kwargs else {}
    kwargs['headers'] = {"X-Mailer": get_mailer_name(), **kwargs['headers']}
    langs = templates[template_name]
    if len(langs.items()) == 1:
        lang, tpls = list(langs.items())[0]
        with language(lang):
            kwargs['headers'] = {"Content-Language": lang, **kwargs['headers']}
            msg = MultiTemplatableEmailMessage(
                subject=subject,
                body=False,
                **kwargs
            )
            for template in tpls:
                msg.attach_alternative(
                    SafeMIMEText(
                        _text=get_template(template['file']).render({
                            'locale': template['locale'],
                            **context,
                        }),
                        _subtype=template['subtype'],
                        _charset=msg.encoding or settings.DEFAULT_CHARSET
                    ), 'unknown/unknown')
        return msg
    msg = MultilingualEmailMessage(subject=subject, **kwargs)
    for lang, tpls in langs.items():
        with language(lang):
            lang_alt = MIMEMultipart(_subtype='alternative')
            lang_alt.add_header("Subject", _(subject))
            for template in tpls:
                lang_alt.attach(
                    SafeMIMEText(get_template(template['file']).render({
                        'locale': template['locale'],
                        **context,
                    }), _subtype=template['subtype']))
            msg.add_language(lang, lang_alt)
    info = MIMEMultipart(_subtype='alternative')
    info.attach(SafeMIMEText(
        get_template("steambird/../templates/mail/multilingual_header.html").render({}),
        _subtype="html", _charset="utf-8"))
    info.attach(SafeMIMEText(
        get_template("steambird/../templates/mail/multilingual_header.plain").render({}),
        _subtype="plain", _charset="utf-8"))
    info.add_header("Content-Disposition", "inline")
    msg.attach(info)
    return msg
def create_multilingual_mail ( template_name : str , subject : str , context : dict , ** kwargs ) -> EmailMessage : _ensure_setup ( ) kwargs [ 'headers' ] = kwargs [ 'headers' ] if 'headers' in kwargs else { } kwargs [ 'headers' ] = { "X-Mailer" : get_mailer_name ( ) , ** kwargs [ 'headers' ] } langs = templates [ template_name ] if len ( langs . items ( ) ) == 1 : lang , tpls = list ( langs . items ( ) ) [ 0 ] with language ( lang ) : kwargs [ 'headers' ] = { "Content-Language" : lang , ** kwargs [ 'headers' ] } msg = MultiTemplatableEmailMessage ( subject = subject , body = False , ** kwargs ) for template in tpls : msg . attach_alternative ( SafeMIMEText ( _text = get_template ( template [ 'file' ] ) . render ( { 'locale' : template [ 'locale' ] , ** context , } ) , _subtype = template [ 'subtype' ] , _charset = msg . encoding or settings . DEFAULT_CHARSET ) , 'unknown/unknown' ) return msg msg = MultilingualEmailMessage ( subject = subject , ** kwargs ) for lang , tpls in langs . items ( ) : with language ( lang ) : lang_alt = MIMEMultipart ( _subtype = 'alternative' ) lang_alt . add_header ( "Subject" , _ ( subject ) ) for template in tpls : lang_alt . attach ( SafeMIMEText ( get_template ( template [ 'file' ] ) . render ( { 'locale' : template [ 'locale' ] , ** context , } ) , _subtype = template [ 'subtype' ] ) ) msg . add_language ( lang , lang_alt ) info = MIMEMultipart ( _subtype = 'alternative' ) info . attach ( SafeMIMEText ( get_template ( "steambird/../templates/mail/multilingual_header.html" ) . render ( { } ) , _subtype = "html" , _charset = "utf-8" ) ) info . attach ( SafeMIMEText ( get_template ( "steambird/../templates/mail/multilingual_header.plain" ) . render ( { } ) , _subtype = "plain" , _charset = "utf-8" ) ) info . add_header ( "Content-Disposition" , "inline" ) msg . attach ( info ) return msg
Creates an instance of EmailMessage.
Creates an instance of EmailMessage .
"""
    Creates an instance of EmailMessage. If multiple languages exist for
    the given template name, it will create an RFC8255_ compatible email, and if
    only one language exists, it will simply send an email in that language,
    without bothering with any multilingual crap.

    As of implementing this method, very few to no email clients support
    RFC8255_ and so it is recommended to either use create_mail with a
    preference language or use this method and only create one set of language
    templates.

    :param template_name: The template that should be used for this email
    :param subject: The subject of this email
    :param context: The context for the template
    :param kwargs: Any other data that should be passed to the EmailMessage
        constructor
    :return: an EmailMessage

    .. _RFC8255: https://tools.ietf.org/html/rfc8255
    """
None
template_name
str
The template that should be used for this email
The template that should be used for this email
subject
str
The subject of this email
The subject of this email
context
dict
The context for the template
The context for the template
kwargs
Any other data that should be passed to the EmailMessage
constructor
Any other data that should be passed to the EmailMessage constructor