Getting started

Bootstrap Drupal

To be able to use all Drupal's functions you need to have them loaded:
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

Don't send 1000s of e-mails

Calling the hooks has one possible side effect. Sending mails. No matter how much you switch off assume there is something that will try and mail out. There are a couple of modules for doing this including Devel. In this case, keeping it light, I just variable_set('smtp_library', 'db_mail.inc'); db_mail.inc just having a function:

function drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers) {
  print "mail to $to about $subject";
  return true;
}

... as it's nice to see what's going on sometimes.