def _send_bulk_mail(recipient_ids, sender_id, intent, email_subject, email_html_body, sender_email, sender_name, instance_id=None):
 _require_sender_id_is_valid(intent, sender_id)
 recipients_settings = user_services.get_users_settings(recipient_ids)
 recipient_emails = [user.email for user in recipients_settings]
 cleaned_html_body = html_cleaner.clean(email_html_body)
 if (cleaned_html_body != email_html_body):
  log_new_error(('Original email HTML body does not match cleaned HTML body:\nOriginal:\n%s\n\nCleaned:\n%s\n' % (email_html_body, cleaned_html_body)))
  return
 raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace('<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>')
 cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body)
 def _send_bulk_mail_in_transaction(instance_id=None):
  sender_name_email = ('%s <%s>' % (sender_name, sender_email))
  email_services.send_bulk_mail(sender_name_email, recipient_emails, email_subject, cleaned_plaintext_body, cleaned_html_body)
  if (instance_id is None):
   instance_id = email_models.BulkEmailModel.get_new_id('')
  email_models.BulkEmailModel.create(instance_id, recipient_ids, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow())
 return transaction_services.run_in_transaction(_send_bulk_mail_in_transaction, instance_id)

def _send_bulk_mail ( recipient_ids , sender_id , intent , email_subject , email_html_body , sender_email , sender_name , instance_id = None ) : _require_sender_id_is_valid ( intent , sender_id ) recipients_settings = user_services . get_users_settings ( recipient_ids ) recipient_emails = [ user . email for user in recipients_settings ] cleaned_html_body = html_cleaner . clean ( email_html_body ) if ( cleaned_html_body != email_html_body ) : log_new_error ( ( 'Original email HTML body does not match cleaned HTML body:\nOriginal:\n%s\n\nCleaned:\n%s\n' % ( email_html_body , cleaned_html_body ) ) ) return raw_plaintext_body = cleaned_html_body . replace ( '<br/>' , '\n' ) . replace ( '<br>' , '\n' ) . replace ( '<li>' , '<li>- ' ) . replace ( '</p><p>' , '</p>\n<p>' ) cleaned_plaintext_body = html_cleaner . strip_html_tags ( raw_plaintext_body ) def _send_bulk_mail_in_transaction ( instance_id = None ) : sender_name_email = ( '%s <%s>' % ( sender_name , sender_email ) ) email_services . send_bulk_mail ( sender_name_email , recipient_emails , email_subject , cleaned_plaintext_body , cleaned_html_body ) if ( instance_id is None ) : instance_id = email_models . BulkEmailModel . get_new_id ( '' ) email_models . BulkEmailModel . create ( instance_id , recipient_ids , sender_id , sender_name_email , intent , email_subject , cleaned_html_body , datetime . datetime . utcnow ( ) ) return transaction_services . run_in_transaction ( _send_bulk_mail_in_transaction , instance_id )
sends an email to all given recipients .