(template_name, recipient_list, extra_context={}, name="", from_email=None, subject="Subject",
               mass=False)
return True
Sends an email using a template.
Sends an email using a template.
Sends an email using a template .
def send_email(template_name, recipient_list, extra_context={}, name="", from_email=None, subject="Subject",
               mass=False):
    """
    Sends an email using a template.
    """

    if not settings.SEND_MAIL:
        return

    # The sender pattern email.
    patt = settings.FROM_EMAIL_PATTERN

    # Final sender email
    from_email = from_email or settings.DEFAULT_FROM_EMAIL
    from_email = patt % (name, from_email)

    # Test the templates exists
    if os.path.isfile(template_name):
        logger.error(f"Missing template: {template_name}")
        return False
    try:
        # Generate emails.
        logger.info(f"sending email from={from_email} recipient_list={recipient_list} template={template_name}")

        # The email template instance
        email = sender.EmailTemplate(template_name)

        # Default context added to each template.
        port = f":{settings.HTTP_PORT}"if settings.HTTP_PORT else ""

        context = dict(domain=settings.SITE_DOMAIN, protocol=settings.PROTOCOL,
                       port=port, name=settings.SITE_NAME, subject=subject)

        # Additional context added to the template.
        context.update(extra_context)

        # Generate and send the email.
        if mass:
            email.send_mass(context=context, from_email=from_email, recipient_list=recipient_list)
        else:
            email.send(context=context, from_email=from_email, recipient_list=recipient_list)

        logging.info(f"email sent to recipient_list={recipient_list} ")

    except Exception as exc:
        logger.error(f"send_email error: {exc}")
        return False

    return True
def send_email ( template_name , recipient_list , extra_context = { } , name = "" , from_email = None , subject = "Subject" , mass = False ) : if not settings . SEND_MAIL : return # The sender pattern email. patt = settings . FROM_EMAIL_PATTERN # Final sender email from_email = from_email or settings . DEFAULT_FROM_EMAIL from_email = patt % ( name , from_email ) # Test the templates exists if os . path . isfile ( template_name ) : logger . error ( f"Missing template: {template_name}" ) return False try : # Generate emails. logger . info ( f"sending email from={from_email} recipient_list={recipient_list} template={template_name}" ) # The email template instance email = sender . EmailTemplate ( template_name ) # Default context added to each template. port = f":{settings.HTTP_PORT}" if settings . HTTP_PORT else "" context = dict ( domain = settings . SITE_DOMAIN , protocol = settings . PROTOCOL , port = port , name = settings . SITE_NAME , subject = subject ) # Additional context added to the template. context . update ( extra_context ) # Generate and send the email. if mass : email . send_mass ( context = context , from_email = from_email , recipient_list = recipient_list ) else : email . send ( context = context , from_email = from_email , recipient_list = recipient_list ) logging . info ( f"email sent to recipient_list={recipient_list} " ) except Exception as exc : logger . error ( f"send_email error: {exc}" ) return False return True