How to stop webform from sending an email I'm using Drupal 7.12 / Webform 3

How do I stop email from being sent upon a webform submission? I want to do this conditionally so I need to use a hook. I still want everything else to go through correctly (i.e. confirmation page, db entry for submission).

I see that there are these lines in function webform_client_form_submit($form, &amp;$form_state)

if (!$is_draft &amp;&amp; !$form_state['values']['details']['finished']) {
    $submission = webform_get_submission($node-&gt;webform['nid'], $sid, TRUE);
    webform_submission_send_mail($node, $submission);
  }


How do I hook into that and stop it?
If you go the end of the function webform_submission_send_mail() inside the file webform.submissions.inc (inside weform module's include directory), you'll notice that the webform module using the function drupal_mail() to send the mail.

So a better place to change the behavior of the mail from being sent (alter in Drupal terms) is hook_mail_alter(), which is used to alter an email message created by using drupal_mail() function.

Implementation of the hook to stop the e-mails:

function MODULE_mail_alter(&amp;$message) {
  //You can do your conditional check here and depending on that
  //you can set the value of $message['send'] to false to stop the mail from being sent. 
  //place the line below inside conditional loop, or else it'll stop every mail from being sent ;-)
  $message['send'] = FALSE; 
}


Note: This hook will only work if the mail is generated by drupal_mail(). If you're sending mail by some other menthod, it'll not be invoked. But, by default Webform module uses drupal_mail() as mentioned earlier, so there's nothing to worry :-)
You'll also need to clear the caches to make the change effective.