Answers.Body: <p>This doesn't seem to be a problem with the mail system, as you say it's some custom code which prevented mails being generated or sent.</p>
  
  <p><em>I see you've identified this - great! And yes, all tokens are generated for each email sent, even if they aren't used - so token generators need to handle situations like this.</em></p>
  
  <p>To help others - I've reformatted the backtrace so it's more readable, and removed some personal details (possibly your own).</p>
  
  <p>The real problem here was that the entity, as provided to <a href="https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7.x" rel="nofollow noreferrer"><code>field_get_items()</code></a>, was being passed as FALSE - perhaps because the module had failed to look up a matching user account?</p>
  
  <p>SO instead of (pseudocode) -</p>
  
  <pre><code>$user = esoCiviMail_get_related_user($contact_id);
  $foo = field_get_items('user', $user);
  // generate tokens
  </code></pre>
  
  <p>you'd want to do</p>
  
  <pre><code>if ($user = esoCiviMail_get_related_user($contact_id) {
    $foo = field_get_items('user', $user);
    // generate tokens
  }
  // else { 
  //   ... generate "no-result" default tokens 
  // }
  </code></pre>
  
  <p>Possibly you want the esoCiviMail module to check if a node was correctly found, and if not then return some default (possibly blank) token value to the CiviCRM hook it's implementing.</p>
  
  <p>If the contact really has an email of <code>tim[at]example.com</code> instead of <code>tim@example.com</code> I'd expect this to trigger some issues.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-03T23:15:19.397Z
Answers.Text: Ah, I see the problem was a node lookup not a user lookup - same underlying logic holds.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-03T23:13:48.827Z
Answers.LastActivityDate: 2016-11-03T23:18:59.567Z
Answers.LastEditDate: 2016-11-03T23:18:59.567Z
Answers.UserDisplayName: Chris Burgess
Answers.Body: <p>A custom module triggered this problem.</p>
  
  <pre><code>description =  Define custom tokens CiviMail
  dependencies[] = civicrm
  files[] = esoCiviMail.module
  
  
  function esoCiviMail_civicrm_tokenValues() /* */
  function esoCiviMail_civicrm_tokens(&amp;$tokens) {
  // ...
  $nid=$node*1; //node id of next concert promo page //
  $input_lines="";
  // $node does not resolve--THIS IS BROKEN AFTER CONCERT 1
  $node = node_load($nid);
  $my_field_items = field_get_items('node', $node, 'body');
    if ($my_field_items) {
      $my_field_first_item = reset($my_field_items);
      $input_lines = $my_field_first_item['value'];
    }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-03T22:31:39.227Z
Answers.LastActivityDate: 2016-11-03T23:16:49.473Z
Answers.LastEditDate: 2016-11-03T23:16:49.473Z
Answers.UserDisplayName: TimETown
Body: <p>I had an install of CiviCRM which had CiviMail and all email working fine. I was using sendgrid to deliver the email, and ran out of credits. Unsent mail had piled up in the Civi system and I attempted to clear caches and temporarily had the system in debug mode. Now I can not send mail via CiviMail nor via individual emails selected from a search, for example. Both give the same error about missing bundle property on entity of type node. The only email I can send is the test of the SMTP server settings from /civicrm/admin/setting/smtp?reset=1</p>
  
  <p>This problem started while running 4.6.16. I attempted an upgrade to 4.7.12 and get the same error, so that did not fix it.</p>
  
  <p>entire backtrace message with minor edits for privacy:</p>
  
  <pre><code>LOCATION  http://esoduplicate.evanstonsymphony.org/civicrm/contact/search/advanced?_qf_Email_display=true&amp;qfKey=df6b23737309806ea2bf2ae9b9b9cbc1_2533
  REFERRER  http://esoduplicate.evanstonsymphony.org/civicrm/contact/search/advanced?_qf_Advanced_display=true&amp;qfKey=df6b23737309806ea2bf2ae9b9b9cbc1_2533
  MESSAGE  $backTrace = 
    #0 /path-to-site/sites/all/modules/civicrm/CRM/Core/Error.php(454): CRM_Core_Error::backtrace("backTrace", TRUE) 
    #1 /path-to-site/sites/all/modules/civicrm/CRM/Core/Invoke.php(57): CRM_Core_Error::handleUnhandledException(Object(EntityMalformedException))
    #2 /path-to-site/sites/all/modules/civicrm/drupal/civicrm.module(448): CRM_Core_Invoke::invoke((Array:4)) 
    #3 [internal function](): civicrm_invoke("contact", "search", "advanced") 
    #4 /path-to-site/includes/menu.inc(527): call_user_func_array("civicrm_invoke", (Array:3)) 
    #5 /path-to-site/index.php(21): menu_execute_active_handler() #6 {main}
  
  $Fatal Error Details = array(3) { 
    ["message"]=&gt; string(47) "Missing bundle property on entity of type node." 
    ["code"]=&gt; NULL
    ["exception"]=&gt; object(EntityMalformedException)#269 (7) { 
      ["message":protected]=&gt; string(47) "Missing bundle property on entity of type node." 
      ["string":"Exception":private]=&gt; string(0) "" 
      ["code":protected]=&gt; int(0) 
      ["file":protected]=&gt; string(52) "/path-to-site/includes/common.inc" 
      ["line":protected]=&gt; int(7907) 
      ["trace":"Exception":private]=&gt; array(21) { 
        [0]=&gt; array(4) { 
          ["file"]=&gt; string(69) "/path-to-site/modules/field/field.multilingual.inc" 
          ["line"]=&gt; int(268) 
          ["function"]=&gt; string(18) "entity_extract_ids" 
          ["args"]=&gt; array(2) { 
            [0]=&gt; string(4) "node" 
            [1]=&gt; bool(false) 
          } 
        } 
        [1]=&gt; array(4) {
          ["file"]=&gt; string(59) "/path-to-site/modules/field/field.module" 
          ["line"]=&gt; int(941) 
          ["function"]=&gt; string(14) "field_language" 
          ["args"]=&gt; array(4) { 
            [0]=&gt; string(4) "node" 
            [1]=&gt; bool(false) 
            [2]=&gt; string(4) "body" 
            [3]=&gt; NULL 
          } 
       } 
       [2]=&gt; array(4) { 
         ["file"]=&gt; string(81) "/path-to-site/sites/all/modules/esoCiviMail/esoCiviMail.module" 
         ["line"]=&gt; int(190) 
         ["function"]=&gt; string(15) "field_get_items" 
         ["args"]=&gt; array(3) { 
           [0]=&gt; string(4) "node" 
           [1]=&gt; bool(false) 
           [2]=&gt; string(4) "body" 
         } 
       } 
       [3]=&gt; array(4) { 
         ["file"]=&gt; string(77) "/path-to-site/sites/all/modules/civicrm/CRM/Utils/Hook.php" 
         ["line"]=&gt; int(240) 
         ["function"]=&gt; string(31) "esoCiviMail_civicrm_tokenValues" 
         ["args"]=&gt; array(5) { 
           [0]=&gt; &amp;array(1) { 
             [2]=&gt; array(9) { 
               ["contact_id"]=&gt; string(1) "2" 
               ["sort_name"]=&gt; string(11) "Example, Tim" 
               ["display_name"]=&gt; string(10) "Tim Example" 
               ["do_not_email"]=&gt; string(1) "0" 
               ["preferred_mail_format"]=&gt; string(4) "Both" 
               ["is_deceased"]=&gt; string(1) "0" 
               ["email_id"]=&gt; string(1) "2" 
               ["email"]=&gt; string(19) "tim[at]example.com" 
               ["on_hold"]=&gt; string(1) "0" 
             } 
           } 
           [1]=&gt; array(1) { 
             [0]=&gt; int(2) 
           } 
           [2]=&gt; NULL 
           [3]=&gt; array(0) { } 
           [4]=&gt; NULL 
         } 
       } 
       [4]=&gt; array(6) { 
         ["file"]=&gt; string(88) "/path-to-site/sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php" 
         ["line"]=&gt; int(85) 
         ["function"]=&gt; string(8) "runHooks" 
         ["class"]=&gt; string(14) "CRM_Utils_Hook" 
         ["type"]=&gt; string(2) "-&gt;" 
         ["args"]=&gt; array(9) { 
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-03T16:57:32.697Z
Comments.Text: When I do a quick Google search on the error I get the impression its origin is drupal (specially the entity system). Do you have some extra drupal civicrm modules installed?
Comments.UserDisplayName: Kainuk - CiviCooP
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-03T22:26:53.310Z
Comments.Text: I figured it out. It was a custom module to supply custom tokens which we had written and interacted with CiviMail. I think a date change trigger made the problems both appear on the same day and made debugging harder. Plus I don't really understand why it impacted all mail, even if it used no part of the module and the non-CiviMail part of the system. I guess the hook impacts all mail: esoCiviMail_civicrm_tokens
Comments.UserDisplayName: TimETown
Tags: <civimail><email><error>
Title: Mail system in my install is broken: Missing bundle property on entity of type node
ThreadText: # Mail system in my install is broken: Missing bundle property on entity of type node
  
  (Asked by: username_0 on 2016-11-03)
  
  I had an install of CiviCRM which had CiviMail and all email working fine. I was using sendgrid to deliver the email, and ran out of credits. Unsent mail had piled up in the Civi system and I attempted to clear caches and temporarily had the system in debug mode. Now I can not send mail via CiviMail nor via individual emails selected from a search, for example. Both give the same error about missing bundle property on entity of type node. The only email I can send is the test of the SMTP server settings from /civicrm/admin/setting/smtp?reset=1
  This problem started while running 4.6.16. I attempted an upgrade to 4.7.12 and get the same error, so that did not fix it.
  entire backtrace message with minor edits for privacy:
  LOCATION  http://esoduplicate.evanstonsymphony.org/civicrm/contact/search/advanced?_qf_Email_display=true&qfKey=df6b23737309806ea2bf2ae9b9b9cbc1_2533
  REFERRER  http://esoduplicate.evanstonsymphony.org/civicrm/contact/search/advanced?_qf_Advanced_display=true&qfKey=df6b23737309806ea2bf2ae9b9b9cbc1_2533
  MESSAGE  $backTrace = 
    #0 /path-to-site/sites/all/modules/civicrm/CRM/Core/Error.php(454): CRM_Core_Error::backtrace("backTrace", TRUE) 
    #1 /path-to-site/sites/all/modules/civicrm/CRM/Core/Invoke.php(57): CRM_Core_Error::handleUnhandledException(Object(EntityMalformedException))
    #2 /path-to-site/sites/all/modules/civicrm/drupal/civicrm.module(448): CRM_Core_Invoke::invoke((Array:4)) 
    #3 [internal function](): civicrm_invoke("contact", "search", "advanced") 
    #4 /path-to-site/includes/menu.inc(527): call_user_func_array("civicrm_invoke", (Array:3)) 
    #5 /path-to-site/index.php(21): menu_execute_active_handler() #6 {main}
  
  $Fatal Error Details = array(3) { 
    ["message"]=> string(47) "Missing bundle property on entity of type node." 
    ["code"]=> NULL
    ["exception"]=> object(EntityMalformedException)#269 (7) { 
      ["message":protected]=> string(47) "Missing bundle property on entity of type node." 
      ["string":"Exception":private]=> string(0) "" 
      ["code":protected]=> int(0) 
      ["file":protected]=> string(52) "/path-to-site/includes/common.inc" 
      ["line":protected]=> int(7907) 
      ["trace":"Exception":private]=> array(21) { 
        [0]=> array(4) { 
          ["file"]=> string(69) "/path-to-site/modules/field/field.multilingual.inc" 
          ["line"]=> int(268) 
          ["function"]=> string(18) "entity_extract_ids" 
          ["args"]=> array(2) { 
            [0]=> string(4) "node" 
            [1]=> bool(false) 
          } 
        } 
        [1]=> array(4) {
          ["file"]=> string(59) "/path-to-site/modules/field/field.module" 
          ["line"]=> int(941) 
          ["function"]=> string(14) "field_language" 
          ["args"]=> array(4) { 
            [0]=> string(4) "node" 
            [1]=> bool(false) 
            [2]=> string(4) "body" 
            [3]=> NULL 
          } 
       } 
       [2]=> array(4) { 
         ["file"]=> string(81) "/path-to-site/sites/all/modules/esoCiviMail/esoCiviMail.module" 
         ["line"]=> int(190) 
         ["function"]=> string(15) "field_get_items" 
         ["args"]=> array(3) { 
           [0]=> string(4) "node" 
           [1]=> bool(false) 
           [2]=> string(4) "body" 
         } 
       } 
       [3]=> array(4) { 
         ["file"]=> string(77) "/path-to-site/sites/all/modules/civicrm/CRM/Utils/Hook.php" 
         ["line"]=> int(240) 
         ["function"]=> string(31) "esoCiviMail_civicrm_tokenValues" 
         ["args"]=> array(5) { 
           [0]=> &array(1) { 
             [2]=> array(9) { 
               ["contact_id"]=> string(1) "2" 
               ["sort_name"]=> string(11) "Example, Tim" 
               ["display_name"]=> string(10) "Tim Example" 
               ["do_not_email"]=> string(1) "0" 
               ["preferred_mail_format"]=> string(4) "Both" 
               ["is_deceased"]=> string(1) "0" 
               ["email_id"]=> string(1) "2" 
               ["email"]=> string(19) "tim[at]example.com" 
               ["on_hold"]=> string(1) "0" 
             } 
           } 
           [1]=> array(1) { 
             [0]=> int(2) 
           } 
           [2]=> NULL 
           [3]=> array(0) { } 
           [4]=> NULL 
         } 
       } 
       [4]=> array(6) { 
         ["file"]=> string(88) "/path-to-site/sites/all/modules/civicrm/CRM/Utils/Hook/DrupalBase.php" 
         ["line"]=> int(85) 
         ["function"]=> string(8) "runHooks" 
         ["class"]=> string(14) "CRM_Utils_Hook" 
         ["type"]=> string(2) "->" 
         ["args"]=> array(9) {
  
  **Tags:** civimail, email, error
  
  > **Comments:**
  > **username_1**: When I do a quick Google search on the error I get the impression its origin is drupal (specially the entity system). Do you have some extra drupal civicrm modules installed?  
  > **username_0**: I figured it out. It was a custom module to supply custom tokens which we had written and interacted with CiviMail. I think a date change trigger made the problems both appear on the same day and made debugging harder. Plus I don't really understand why it impacted all mail, even if it used no part of the module and the non-CiviMail part of the system. I guess the hook impacts all mail: esoCiviMail_civicrm_tokens  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-11-03. Score: 3
  
  This doesn't seem to be a problem with the mail system, as you say it's some custom code which prevented mails being generated or sent.
  I see you've identified this - great! And yes, all tokens are generated for each email sent, even if they aren't used - so token generators need to handle situations like this.
  To help others - I've reformatted the backtrace so it's more readable, and removed some personal details (possibly your own).
  The real problem here was that the entity, as provided to field_get_items(), was being passed as FALSE - perhaps because the module had failed to look up a matching user account?
  SO instead of (pseudocode) -
  $user = esoCiviMail_get_related_user($contact_id);
  $foo = field_get_items('user', $user);
  // generate tokens
  
  you'd want to do
  if ($user = esoCiviMail_get_related_user($contact_id) {
    $foo = field_get_items('user', $user);
    // generate tokens
  }
  // else { 
  //   ... generate "no-result" default tokens 
  // }
  
  Possibly you want the esoCiviMail module to check if a node was correctly found, and if not then return some default (possibly blank) token value to the CiviCRM hook it's implementing.
  If the contact really has an email of tim[at]example.com instead of tim@example.com I'd expect this to trigger some issues.
  
  > **Comments:**
  > **username_2**: Ah, I see the problem was a node lookup not a user lookup - same underlying logic holds.  
  
  ---
  
  ### Answer by username_0 on 2016-11-03. Score: 1
  
  A custom module triggered this problem.
  description =  Define custom tokens CiviMail
  dependencies[] = civicrm
  files[] = esoCiviMail.module
  
  
  function esoCiviMail_civicrm_tokenValues() /* */
  function esoCiviMail_civicrm_tokens(&$tokens) {
  // ...
  $nid=$node*1; //node id of next concert promo page //
  $input_lines="";
  // $node does not resolve--THIS IS BROKEN AFTER CONCERT 1
  $node = node_load($nid);
  $my_field_items = field_get_items('node', $node, 'body');
    if ($my_field_items) {
      $my_field_first_item = reset($my_field_items);
      $input_lines = $my_field_first_item['value'];
    }
  }
  
  
  ---
  
  