Thanks James, here's my working code from the task's execute() method
in case it helps anyone else:

  $configuration = ProjectConfiguration::getApplicationConfiguration
('climategp', 'dev', false);
    sfContext::createInstance($configuration);

    $configuration->loadHelpers('Partial');

    try
    {
      // Create the mailer and message objects
      $mailer = new Swift(new Swift_Connection_NativeMail());
      $message = new Swift_Message('Test mail subject');

      $mailContext = array('name' => 'John Doe');
      $html = get_partial('email/contact', $mailContext);

      // Render message parts
      $message->attach(new Swift_Message_Part($html, 'text/html'));

      // Send
      $mailer->send($message, $mailTo, $mailFrom);
      $mailer->disconnect();
    }
    catch (Exception $e)
    {
      $mailer->disconnect();

      // handle errors there
    }

On Mar 5, 5:41 am, James Cauwelier <[email protected]> wrote:
> Here 's some code of mine, although I use it on sf1.1.  It should work
> on 1.2 as far as I know
>
> <?php
>
> class resetPasswordTask extends sfPropelBaseTask
> {
>   protected function configure()
>   {
>     $this->namespace        = 'send';
>     $this->name             = 'resetPassword';
>     $this->briefDescription = 'Send reset password emails';
>     $this->detailedDescription = <<<EOF
> The [send_confirmation|INFO] task does things.
> Call it with:
>
>   [php symfony send_confirmation|INFO]
> EOF;
>     $this->addArgument('application', sfCommandArgument::REQUIRED,
> 'The application name');
>     // add other arguments here
>     $this->addOption('env', null, sfCommandOption::PARAMETER_REQUIRED,
> 'The environment', 'dev');
>     $this->addOption('connection', null,
> sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel');
>     // add other options here
>   }
>
>   protected function execute($arguments = array(), $options = array())
>   {
>     // Database initialization
>     $databaseManager = new sfDatabaseManager($this->configuration);
>     $connection = Propel::getConnection($options['connection'] ?
> $options['connection'] : '');
>
>                 // you need a context to load the partial helper
>                 $context = sfContext::createInstance($this->configuration);
>                 sfLoader::loadHelpers('Partial');
>
>                 ...
>
>                 while ($activation_count > 0 AND $sent < $max_sent)
>                 {
>                         ...
>                         $mailbody = get_partial ('mailer/resetPassword', 
> array('activation'
> => $activation));
>                         ...
>                 }
>   }
>
> }
>
> On Mar 4, 1:34 pm, danielwinter <[email protected]> wrote:
>
> > Wanting to send emails using templates from a CLI task.The cookbook
> > says:
>
> > "You'll need to use get_partial() and get_component() functions in
> > PartialHelper instead of sfAction::getPartial() and
> > sfAction::getComponent() methods."
>
> > But has anyone actually got this to work?!?!
> > cheers
> > dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to