public function testSendEmailWithFailedAttempts()
 {
     $noOfRecipients = 6;
     $communication = $this->createCommunicationWithMultipleRecipients(new RhubarbDateTime("now"), $noOfRecipients);
     $communicationEmail = $communication->Items[$noOfRecipients - 1];
     $communicationEmail->Sent = true;
     $communicationEmail->save();
     CommunicationProcessor::sendCommunication($communication);
     $this->assertCount(1, UnitTestingEmailProvider::GetLastEmail()->getRecipients(), "Communication scaffold should have unwrapped the recipients to individual email items. Each email item" . " should have just 1 recipient");
     $this->assertEquals("*****@*****.**", current(UnitTestingEmailProvider::GetLastEmail()->getRecipients())->email);
 }
 public function execute(BackgroundTaskStatus $status)
 {
     $status->Message = "Processing Communications to be sent";
     $status->save();
     $communicationID = $status->TaskSettings["CommunicationID"];
     if (!$communicationID) {
         throw new ImplementationException("Communication Background Task must have a Communication ID");
     }
     $communication = new Communication($communicationID);
     CommunicationProcessor::sendCommunication($communication);
 }
 public function testDraftPackageCantSend()
 {
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $this->package->title = "A test communication";
     $communication = $this->package->draft();
     $sent = CommunicationProcessor::sendCommunication($communication);
     $this->assertFalse($sent, "Draft communications shouldn't send");
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $communicationID = $input->getArgument('communicationID');
     if (isset($communicationID)) {
         $communication = new Communication($communicationID);
         CommunicationProcessor::sendCommunication($communication);
     } else {
         $unsentCommunicationsArray = Communication::findUnsentCommunications();
         foreach ($unsentCommunicationsArray as $communication) {
             CommunicationProcessor::sendCommunication($communication);
         }
     }
 }
 protected function createSubLeaves()
 {
     $communicationItems = $this->model->restCollection;
     if ($this->model->archive) {
         $communicationItems->filter(new Not(new Equals('Status', 'Not Sent')));
     }
     $communicationItems->intersectWith(Communication::find(), 'CommunicationID', 'CommunicationID', ['Title', 'DateToSend']);
     $this->registerSubLeaf($table = new Table($communicationItems->addSort('DateCreated', false)), $searchPanel = new CommunicationItemSearchPanel('SearchPanel'), $sendAllButton = new Button('SendAllCommunicationsButton', 'Send All Communications Now', function () {
         foreach (Communication::findUnsentCommunications() as $unsentCommunication) {
             CommunicationProcessor::sendCommunication($unsentCommunication, true);
         }
         throw new ForceResponseException(new RedirectResponse('./'));
     }), new CommunicationItemCollectionCheckbox('EnableSendingEmails'));
     $sendAllButton->setConfirmMessage('Are you sure you want to send all scheduled emails?');
     $table->bindEventsWith($searchPanel);
     $table->columns = ['#' => 'CommunicationItemID', 'Title' => '{Title}', 'Recipient', 'DateCreated', 'Date to Send' => new DateColumn('DateToSend', 'Date to Send', CommunicationDecorator::DATE_FORMAT), 'DateSent', 'Status', '' => '<a class="view-content-button" data-id="{CommunicationItemID}" href="#ViewContent">View Content</a>'];
 }