Send email with custom tokens on event? I am trying to make a rule which when acted upon will send an email with custom details based on the rule arguments.

I made my rule event and that's all working fine it shows up, but when I add an action to "Send mail" and then look at all of the Replacement patterns non of my tokens show up, only site-information tokens show up.

Token Functions

/**
 * Implementation of hook_token_list()
 */
function mahjong_token_list($type = 'all') {
  if ($type == 'all' || $type == 'mahjong') {
    $tokens['mahjong'] = array(
      'package_name' =&gt; t('The name of the package'),
    );
  }

  return $tokens;
}

/**
 * Implementation of hook token api
 */
function mahjong_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();
  var_dump($object);
  if ($object) {
    if ($type == 'mahjong') {
      $tokens = array(
        'user_name' =&gt; $object-&gt;name,
        'user_email' =&gt; $object-&gt;email,
        'user_score' =&gt; $object-&gt;score,
      );
    }
  }

  return $tokens;
}


Rules Function

function mahjong_rules_event_info() {
  return array(
    'mahjong_won' =&gt; array(
      'label' =&gt; t('A person won the mahjong game.'),
      'module' =&gt; 'mahjong',
      'group' =&gt; 'Rules',
      'arguments' =&gt; array(
        'user' =&gt; array('type' =&gt; 'mahjong', 'label' =&gt; t('The user who won the mahjong game.')),
      ),
    ),
  );
}


What am I doing wrong? How can I get the data from the rules argument pass to the action to send an email?
If "mahjong" is just an arbitrary object type, you need to declare it to Rules using hook_rules_data_info and specify the "token type" so that Rules knows what to pass to the token API.

But if the "mahjong" object is a Drupal User entity, you shouldn't need to implement hook_token_* at all.

Instead, when you define your Rules event, the argument should be of type "user". Rules will then know what fields are defined on the entity.