0

In Drupal 7...

I am trying to find a solution to disable the sending of the user mail register by admin for certain roles. I have scoured the internet and have come up with using a combo of mailcontrol and Rules or custom code in my module.

I'm using Rules to send the message. I didn't want to completely disable the welcome email message for the other roles.

How can I create this functionality of sending the system mail to some users but not others? (either programmatically or via Rules)

I have a custom module already, so I used the following hook but nothing happened. I still get the welcome message.

function myMod_fields_user_mail_notify($op, $account, $language = NULL) {

 $notify = variable_get('user_mail_' . $op . '_notify', $default_notify);

if (in_array('Administrator', $user->roles)) {
  if ($op == 'register_admin_created') {
   //don't send system email we'll do this with another rule.
    variable_set('user_mail_register_admin_created_notify', false);
  }
  else if ($notify) {
  $params['account'] = $account;
  $language = $language ? $language : user_preferred_language($account);
  $mail = drupal_mail('user', $op, $account->mail, $language, $params);
}
return empty($mail) ? NULL : $mail['result'];
 }
}
1
  • another suggestion that I have already thought about, was to use mailcontrol and rules to granular set messages for specific roles, avoiding the welcome message for all roles. The problem with this approach is that the one-time-login url can not be properly "tokenized" it seems to only work out of the box with the built in welcome message field. This is why I want to leave that alone
    – MRC
    Commented Jan 9, 2017 at 17:10

1 Answer 1

0

I kind of stumbled on this after nobody answered my question. (I was desperate)

The solutions is to:

  1. Edit your welcome email, under Account Settings.
  2. Enable Mail Control and disable the welcome email. This content is saved in the database, so don't worry about losing anything.

  3. Create a new Rule to react on a new event: After saving a new user account

  4. Add in your condition: User has Role && User is being Notified.
  5. Under Actions: Send Account E-mail.
  6. Under E-mail Type: Choose Welcome E-mail.
  7. Save! Clear Cache! Get More Coffee!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.