def _send_messages(email_messages):
    connection = _get_real_backend()

    # Create a messages on a database for correct
    # tracking of their status.
    email_models = [models.Message.from_email_message(email, save=True)
                    for email in email_messages]

    # Open connection for send all messages
    connection.open()
    try:
        sended_counter = 0
        for email, model_instance in zip(email_messages, email_models):
            if hasattr(email, "priority"):
                if email.priority <= models.PRIORITY_LOW:
                    model_instance.priority = email.priority
                    model_instance.status = models.STATUS_PENDING
                    model_instance.save()
                    sended_counter += 1
                    continue

            sended_counter += _safe_send_message(model_instance, connection)
    finally:
        connection.close()
    return sended_counter
dataset/ETHPy150Open bameda/djmail/djmail/core.py/_send_messages/original