human
Write me a the Python code you requested given the following:
Complete the below
def _send_email(recipient_id, sender_id, intent, email_subject, email_html_body, sender_email, bcc_admin=False, sender_name=None, reply_to_id=None):

    ''''Sends an email to the given recipient.
    This function should be used for sending all user-facing emails.
    Raises an Exception if the sender_id is not appropriate for the given
    intent. Currently we support only system-generated emails and emails
    initiated by moderator actions.
    Args:
    recipient_id: str. The user ID of the recipient.
    sender_id: str. The user ID of the sender.
    intent: str. The intent string for the email, i.e. the purpose/type.
    email_subject: str. The subject of the email.
    email_html_body: str. The body (message) of the email.
    sender_email: str. The sender\'s email address.
    bcc_admin: bool. Whether to send a copy of the email to the admin\'s
    email address.
    sender_name: str or None. The name to be shown in the "sender" field of
    the email.
    reply_to_id: str or None. The unique reply-to id used in reply-to email
    address sent to recipient.'
    '''
assistant
#Here is the Python code you requested.
    if (sender_name is None):
        sender_name = EMAIL_SENDER_NAME.value
    _require_sender_id_is_valid(intent, sender_id)
    recipient_email = user_services.get_email_from_user_id(recipient_id)
    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)
    if email_models.SentEmailModel.check_duplicate_message(recipient_id, email_subject, cleaned_plaintext_body):
        log_new_error(('Duplicate    email:\nDetails:\n%s    %s\n%s\n\n' % (recipient_id, email_subject, cleaned_plaintext_body)))
        return
    def _send_email_in_transaction():
        sender_name_email = ('%s    <%s>' % (sender_name, sender_email))
        email_services.send_mail(sender_name_email, recipient_email, email_subject, cleaned_plaintext_body, cleaned_html_body, bcc_admin, reply_to_id=reply_to_id)
        email_models.SentEmailModel.create(recipient_id, recipient_email, sender_id, sender_name_email, intent, email_subject, cleaned_html_body, datetime.datetime.utcnow())
    return transaction_services.run_in_transaction(_send_email_in_transaction)