title: CakePHP using Email component from Shell cronjob
body: <p>I'm trying to send an email from a CakePHP shell just as you would from the Controller. </p>
  
  <p>Most of the code below was adapted from <a href="http://bakery.cakephp.org/articles/Jippi/2007/12/02/emailcomponent-in-a-cake-shell" rel="noreferrer">this dated article on the Bakery</a> and it's comments. The email is sending, however the line <code>$controller-&gt;set('result', $results[$i]);</code> throws the following notices:</p>
  
  <blockquote>
    <p>Notice: Undefined property:
    View::$webroot in
    /home/jmccreary/www/intranet.sazerac.com/cakephp/cake/libs/view/view.php
    on line 813</p>
    
    <p>PHP Notice:  Undefined
    variable: result in
    /home/jmccreary/www/intranet.sazerac.com/cakephp/app/views/elements/email/text/nea/task_reminder_it.ctp
    on line 2</p>
  </blockquote>
  
  <p>So I'm not getting any of the variables passed to my email view.</p>
  
  <p>How can I do this, ideally following the Cake conventions?</p>
  
  <pre><code>class NotificationShell extends Shell {
      var $uses = array('Employee', 'Task');
  
      function main() {
          // run if no action is passed
      }
  
      function nea_task_reminder() {
          // build Task to Employee relationship
          $this-&gt;Task-&gt;bindModel(array('belongsTo' =&gt; array('Employee' =&gt; array('className' =&gt; 'Employee', 'foreignKey' =&gt; 'object_id'))));
          $results = $this-&gt;Task-&gt;find('all', array('conditions' =&gt; array('application_id' =&gt; 1, 'completed_by_id' =&gt; 0), 'contain' =&gt; array('Employee' =&gt; array('Contact', 'Position'))));
  
          $count = count($results);
          if ($count) {
              App::import('Core', 'Controller');
              App::import('Component', 'Email');
              $controller =&amp; new Controller();
              $email =&amp; new EmailComponent();
              $email-&gt;startup($controller);
  
              // send email
              $email-&gt;from = Configure::read('Email.from');
              $email-&gt;to = 'jmccreary@whatever.com';
              $email-&gt;replyTo = 'no-reply@whatever.com';
              $email-&gt;template = 'nea/task_reminder_it';
              $email-&gt;sendAs = 'text';
  
              for ($i = 0; $i &lt; $count; ++$i) {
                  $email-&gt;subject = 'NEA Notification: Task Reminder for ' . $results[$i]['Employee']['Contact']['full_name'];
                  $controller-&gt;set('result', $results[$i]);
                  $email-&gt;send();
              }
          }
      }
  }
  </code></pre>