protected function execute(InputInterface $input, OutputInterface $output)
 {
     $sendingId = $input->getArgument("sendingId");
     $tmpStore = Model\Tool\TmpStore::get($sendingId);
     if (empty($tmpStore)) {
         Logger::alert("No sending configuration for {$sendingId} found. Cannot send newsletter.");
         exit;
     }
     $data = $tmpStore->getData();
     if ($data['inProgress']) {
         Logger::alert("Cannot send newsletters because there's already one active sending process.");
         exit;
     }
     $data['inProgress'] = 1;
     $tmpStore->setData($data);
     $tmpStore->update();
     $document = Model\Document\Newsletter::getById($data['documentId']);
     $addressSourceAdapterName = $data['addressSourceAdapterName'];
     $adapterParams = $data['adapterParams'];
     $adapterClass = "\\Pimcore\\Document\\Newsletter\\AddressSourceAdapter\\" . ucfirst($addressSourceAdapterName);
     /**
      * @var $addressAdapter \Pimcore\Document\Newsletter\AddressSourceAdapterInterface
      */
     $addressAdapter = new $adapterClass($adapterParams);
     if ($document->getSendingMode() == Newsletter::SENDING_MODE_BATCH) {
         $this->doSendMailInBatchMode($document, $addressAdapter, $sendingId);
     } else {
         $this->doSendMailInSingleMode($document, $addressAdapter, $sendingId);
     }
     Model\Tool\TmpStore::delete($sendingId);
 }
 public function sendTestAction()
 {
     $document = Document\Newsletter::getById($this->getParam("id"));
     $addressSourceAdapterName = $this->getParam("addressAdapterName");
     $adapterParams = json_decode($this->getParam("adapterParams"), true);
     $adapterClass = "\\Pimcore\\Document\\Newsletter\\AddressSourceAdapter\\" . ucfirst($addressSourceAdapterName);
     /**
      * @var $addressAdapter \Pimcore\Document\Newsletter\AddressSourceAdapterInterface
      */
     $addressAdapter = new $adapterClass($adapterParams);
     $sendingContainer = $addressAdapter->getParamsForTestSending($this->getParam("testMailAddress"));
     $mail = \Pimcore\Tool\Newsletter::prepareMail($document);
     \Pimcore\Tool\Newsletter::sendNewsletterDocumentBasedMail($mail, $sendingContainer);
     $this->_helper->json(["success" => true]);
 }