[docs]defemail_send(text_template:str,html_template:str,data:Mapping[str,object],subject:str,emails:Collection[str],# pylint: disable=unsubscriptable-objectheaders:Mapping[str,str]=None,# pylint: disable=unsubscriptable-objectbcc:bool=False,*,custom_logger:logging.Logger=None,)->EmailMultiAlternatives:"""Send an HTML/Plaintext email with the following fields. If we are not in production and settings.FORCE_EMAIL_SEND is not set, does not actually send the email Args: text_template: URL to a Django template for the text email's contents html_template: URL to a Django template for the HTML email's contents data: The context to pass to the templates subject: The subject of the email emails: The addresses to send the email to headers: A dict of additional headers to send to the message custom_logger: An optional logger to use instead of the Django logger Returns: The email object that was created (and sent if we're in production or settings.FORCE_EMAIL_SEND is set) """logger=custom_loggerifcustom_loggerisnotNoneelseglobals()["logger"]# pylint: disable=redefined-outer-nametext=get_template(text_template)html=get_template(html_template)text_content=text.render(data)html_content=html.render(data)subject=settings.EMAIL_SUBJECT_PREFIX+subjectheaders={}ifheadersisNoneelseheadersifnotemails:logger.debug("Email list is empty; not sending")returnEmailMultiAlternatives(subject,text_content,settings.EMAIL_FROM,emails,headers=headers)email_groups=[emails[i:i+800]foriinrange(0,len(emails),800)]email_msg=[]forgroupinemail_groups:ifbcc:msg=EmailMultiAlternatives(subject,text_content,settings.EMAIL_FROM,[settings.EMAIL_FROM],headers=headers,bcc=group)else:msg=EmailMultiAlternatives(subject,text_content,settings.EMAIL_FROM,group,headers=headers)msg.attach_alternative(html_content,"text/html")email_msg.append(msg)logger.debug("Emailing %s to %s in %d separate emails",subject,emails,len(email_msg))# We only want to actually send emails if we are in production or explicitly force sending.ifsettings.PRODUCTIONorsettings.FORCE_EMAIL_SEND:formsginemail_msg:msg.send()else:logger.debug("Refusing to email in non-production environments. To force email sending, enable settings.FORCE_EMAIL_SEND.")returnemail_msg