Why is Rules Action "Create Linked Drupal User Account" not working? I’m using Drupal 7.56 and CiviCRM 4.6.31.

I’ve been using Rules in Drupal to create a Drupal User Account linked to the CiviCRM contact created.
But it's failing. I'm getting the following error:


  Cannot create user, email: invalid!!


This is the export of the Rule:

{ "rules_create_a_drupaluser_for_an_civicrmcontact" :
    {
        "LABEL" : "Create a Drupal user for an CiviCRM contact",
        "PLUGIN" : "reaction rule",
        "OWNER" : "rules",
        "REQUIRES" : [ "civicrm" ],
        "ON" : { "civicrm_contact_create" : [] },
        "IF" : [
          { "NOT civicrm_entity_user_exists" : { "civicrm_contact" : [ "civicrm_contact" ] } }
        ],
        "DO" : [
          {
            "civicrm_entity_action_create_user" : {
              "USING" : {
                "civicrm_contact" : [ "civicrm_contact" ],
                "is_active" : "1",
                "notify" : "0",
                "signin" : "0",
                "username_format" : "email"
              },
              "PROVIDE" : { "civicrm_user" : { "civicrm_user" : "Created Drupal User" } }
            }
          }
        ]
    }
}


It was working some time ago. 

The link where I downloaded the civicrm_entity (release 7.x-2.0) is:
https://www.drupal.org/project/civicrm_entity/releases

For your convenience I've added the source code for the Rules Action civicrm_entity_action_create_user:

function civicrm_entity_action_create_user ($contact, $is_active, $notify = FALSE, $signin = FALSE, $username_format = 'first last') {

  if (!is_array($contact)) {

    // Perhaps we should be accepting object rather than array here?
    $contact = (array) $contact;
  }

  // We'll use the civicrm sync mechanism to see if Civi can match the
  // contact to an existing user.

  // Don't think this is a great approach but will use for now - could
  // just create the user but no great support for that yet.

  if (empty($contact['display_name']) || empty($contact['email']) || empty($contact['first_name']) || empty($contact['last_name'])) {

    $contact = civicrm_api('contact', 'getsingle', array(
      'version' =&gt; 3,
      'id' =&gt; $contact['id'],
      'sequential' =&gt; 1,
      'return' =&gt; 'email,display_name,first_name,last_name',
    ));
  }

  if (!is_string($contact['email']) &amp;&amp; isset($contact['email'][0]-&gt;email)) {

    $contact['email'] = $contact['email'][0]-&gt;email;
  }

  // @TODO What happens if they don't have an email at this point?

  // An email is a pre-requisite for a Drupal account, so the action
  // fails if they don't have an email.

  if (filter_var($contact['email'], FILTER_VALIDATE_EMAIL) === FALSE) {

    drupal_set_message(filter_xss("Cannot create user, email: " . $contact['email'] . " invalid!!") , 'error');

    watchdog('civicrm_entity', 'Cannot create user, email %mail invalid.', array('%mail' =&gt; $contact['email']), WATCHDOG_ERROR);
    return FALSE;
  }


And here is where the error raises.

These is the Rules evaluation log:

Reacting on event CiviCRM Contact has been created.

 Evaluating conditions of rule Create a Drupal user for an CiviCRM contact. 

 The condition civicrm_entity_user_exists evaluated to FALSE

 AND evaluated to TRUE.

Rule Create a Drupal user for an CiviCRM contact fires.

   Rule Create a Drupal user for an CiviCRM contact fires.

   Evaluating the action civicrm_entity_action_create_user.

   Evaluating the action devel_debug.

   Rule Create a Drupal user for an CiviCRM contact has fired.

Finished reacting on event CiviCRM Contact has been created.


And the Log Message gets this Error:

MESSAGE "**Cannot create user, email invalid.**"


Does anyone have any clue about what might be happening?
The explanation for the issue you're facing is within the comment lines of the Rules Action you included iin your question, i.e.: 

  // @TODO What happens if they don't have an email at this point?

  // An email is a pre-requisite for a Drupal account, so the action
  // fails if they don't have an email.


The eMail ID for the CiviCRM contact you're using appears to be missing. So try again with a similar testcase, but make sure that for the CiviCRM contact some eMail Id is entered.

This probably also explains the "It was working some time ago": chances are that it was working, since you were using a CiviCRM contact for which an eMail ID was available.