title: Send email from command line in symfony2
body: <p>I need to render a twig template from a command class in symfony2.</p>
  
  <pre class="lang-php prettyprint-override"><code>namespace IT\bBundle\Command;
  
  use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  use Symfony\Component\Console\Input\InputArgument;
  use Symfony\Component\Console\Input\InputInterface;
  use Symfony\Component\Console\Input\InputOption;
  use Symfony\Component\Console\Output\OutputInterface;
  
  class CronCommand extends ContainerAwareCommand
  {
      protected function configure()
      {
          $this
              -&gt;setName('send:emails')
              -&gt;setDescription('Envio programado de emails');
      }
  
      protected function execute(InputInterface $input, OutputInterface $output)
      {
          $message = \Swift_Message::newInstance()
              -&gt;setSubject('bla bla')
              -&gt;setFrom('x@x.com')
              -&gt;setTo('x@gmail.com')
              -&gt;setCharset('UTF-8')
              -&gt;setContentType('text/html')       
              -&gt;setBody($this-&gt;renderView('mainBundle:Email:default.html.twig'));
  
          $this-&gt;getContainer()-&gt;get('mailer')-&gt;send($message);
          $output-&gt;writeln('Enviado!');
      }
  }
  </code></pre>
  
  <p>But when I execute the command <code>php app/console send:emails</code> I get the following error:</p>
  
  <blockquote>
    <p>Fatal error: Call to undefined method <code>IT\bBundle\Command\CronCommand::renderView()</code></p>
  </blockquote>
  
  <p>How can I render the view?</p>