Maybe you should take a look at drupal_mail
function
// Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
drupal_alter('mail', $message);
// The original caller requested sending. Sending was canceled by one or
// more hook_mail_alter() implementations. We set 'result' to NULL, because
// FALSE indicates an error in sending.
if (empty($message['send'])) {
$message['result'] = NULL;
}
Then hook_mail_alter
From description
$message: An array containing the message data. Keys in this array include:
'send': Set to FALSE to abort sending this email message.
'params': An array of optional parameters supplied by the caller of drupal_mail() that is used to build the message before
hook_mail_alter()
is invoked.
Parameters usually contain $message['params']['account'], so you can abort e-mail sending by role or other way.
Example (not tested) aborting any e-mail to account with specific role:
function MY_MODULE_mail_alter(&$message) {
$role = 'CUSTOM_ROLE';
if (!isset($message['params']['account'])) return;
$account = $message['params']['account'];
if (is_array($account->roles) && in_array($role, array_values($account->roles))) {
$message['send'] = NULL;
}
}
There is an issue then sending custom e-mails, $account contain sender account object, not receiver. But for default notifications this should work. So don't forget to check $message['key'] for default notification types from _user_mail_notify, it always provide $account object mail is sending to:
'register_admin_created': Welcome message for user created by the admin.
'register_no_approval_required': Welcome message when user self-registers.
'register_pending_approval': Welcome message, user pending admin approval.
'password_reset': Password recovery request.
'status_activated': Account activated.
'status_blocked': Account blocked.
'cancel_confirm': Account cancellation request.
'status_canceled': Account canceled.