def METHOD_NAME(sender, subject, body, all_users, depid, experiment, role, test):
    """Create and send mails.
    The `subject` and `body` options are prompts, so they should not be
    provided in the command. If `test` exists, it will be used to send the mail
    to it. The 3 recipient options are mutually exclusive, and can't be used
    together. The `--with-role` option can only be used in the context of
    record users.
    Examples:
        cap mail send --all-users
        cap mail send --users-from-experiment cms
        cap mail send --users-from-record DEPID
        cap mail send --users-from-record DEPID --with-role read
    And with `--test`:
        cap mail send --test testmail@cern.ch --all-users
    """
    if not sender:
        sender = current_app.config['MAIL_DEFAULT_SENDER']
    if all_users:
        recipients = get_all_users()
    elif experiment:
        recipients = get_users_by_experiment(experiment)
    else:
        recipients = get_users_by_record(depid, role=role)
    # if test is provided, the mail will not be sent to the actual recipients
    recipient_list = [test] if test else recipients
    # TODO: Support templates/context and find the
    #       different ways to provide the data
    msg = Message(sender=sender, bcc=recipient_list, subject=subject, body=body)
    current_app.extensions['mail'].METHOD_NAME(msg)
    click.secho(
        f"From {sender}\n"
        f"To {recipients}\n"
        f"Subject: {subject}\n"
        f"Body: {body}",
        fg='green',
    )