【问题标题】:Symfony task mailingSymfony 任务邮件
【发布时间】:2011-08-10 13:55:46
【问题描述】:

我使用 symfony 1.4.11 ,我需要从任务中发送邮件。我使用this 文章。所以我有下一个简单的代码,例如:

class mailerSendTask extends sfBaseTask
{

  protected function configure()
  {

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      // add your own options here

    ));

    $this->namespace        = 'mailer';
    $this->name             = 'send';
    $this->briefDescription = 'Ads mailling';
    $this->detailedDescription = <<<EOF
The [mailer:send|INFO] 
    Mailing links to new ads for all users who are subscribed.

Call it with:
  [php symfony mailer:send|INFO]
EOF;


  }

  protected function execute($arguments = array(), $options = array())
  {

    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

    $context = sfContext::createInstance($this->configuration);
    $this->configuration->loadHelpers('Partial');

    $message = $this->getMailer()->compose('no-reply@some.com', 'mymailgmail.com', 'New Ads');

               // generate HTML part
            $context->getRequest()->setRequestFormat('html');
            $html  ='some text';// get_partial('ads/mailing',array ('user_id'=>$user_id));
            $message->setBody($html, 'text/html');

             // send the message

            $this->getMailer()->sendNextImmediately()->send($message);     
}

}

所以任务工作没有错误,我有:

>> sfPatternRouting Connect sfRoute "sf_guard_signin" (/login)
>> sfPatternRouting Connect sfRoute "sf_guard_signout" (/logout)
>> sfPatternRouting Connect sfRoute "sf_guard_password" (/request_password)
>> sfPatternRouting Match route "homepage" (/) for / with parameters array (  'module' => 'main',  'action' => 'index',)

但是这些信件没有发送到我的电子邮件...也许我的代码不正确?

【问题讨论】:

    标签: symfony1 swiftmailer symfony-1.4 mailing


    【解决方案1】:

    查看这篇文章:http://www.symfony-project.org/more-with-symfony/1_4/en/04-Emails#chapter_04_configuration

    也许您在devtest 环境中将delivery_strategy 设置为none

    【讨论】:

    • 他默认在dev中运行,默认策略是没有的。他应该在 prod 环境中运行它。
    • 我很愚蠢。是的,我有 delivery_strategy in dev none 策略。我的任务在 dev 中运行。
    猜你喜欢
    • 2016-08-04
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多