예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification)
 {
     $failedSms = [];
     $tos = $notification->getTo();
     if (empty($tos)) {
         throw new NotificationFailedException('No recipients specified');
     }
     foreach ($tos as $to) {
         $skebbySms = SkebbySms::create()->addRecipient($to)->setText($notification->getContent());
         $result = new Result('skebby', $this->name, Result::OK);
         try {
             $response = $this->skebby->send($skebbySms)[0];
             $result->setResponse($response);
             if (!$response->isSuccessful()) {
                 $result->setResult(Result::FAIL);
                 $failedSms[] = ['to' => $to, 'error_message' => $response->getErrorMessage()];
             }
         } catch (\Exception $e) {
             $result->setResult(Result::FAIL)->setResponse($e);
             $failedSms[] = ['to' => $to, 'error_message' => $e->getMessage()];
         }
         $notification->addResult($result);
     }
     if (count($tos) === count($failedSms)) {
         throw new NotificationFailedException('All the sms failed to be send', ['failed_sms' => $failedSms]);
     }
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification)
 {
     /** @var Email $notification */
     if (null === $this->converter) {
         $this->converter = new SwiftMailerConverter();
     }
     if (!empty($notification->getTo()) || !empty($notification->getCc()) || !empty($notification->getBcc())) {
         $email = $this->converter->convert($notification);
         $result = $this->mailer->send($email);
         $res = new Result('swiftmailer', $this->getName(), $result > 0);
         $res->setResponse($result);
         $notification->addResult($res);
         if (0 === $result) {
             throw new NotificationFailedException('Mailer reported all recipient failed');
         }
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification)
 {
     if (!class_exists('Swift_Message')) {
         throw new \RuntimeException('You need to install swift mailer to use mailgun transport');
     }
     /** @var Email $notification */
     $message = \Swift_Message::newInstance($notification->getSubject())->setFrom($notification->getFrom());
     foreach ($notification->getParts() as $part) {
         $message->attach(\Swift_MimePart::newInstance($part->getContent(), $part->getContentType()));
     }
     foreach ($notification->getAttachments() as $attachment) {
         $message->attach(\Swift_Attachment::newInstance($attachment->getContent(), $attachment->getName(), $attachment->getContentType()));
     }
     $postData = ['o:tag' => $notification->getTags()];
     foreach ($notification->getMetadata() as $key => $value) {
         $postData['v:' . $key] = $value;
     }
     if ($recipientVariables = $notification->getRecipientVariables()) {
         $postData['recipient-variables'] = json_encode($recipientVariables);
     }
     $failed = [];
     $success = [];
     $to = array_merge(array_values($notification->getTo()), array_values($notification->getCc()), array_values($notification->getBcc()));
     if (!empty($to)) {
         foreach (array_chunk($to, 1000) as $to_chunk) {
             $result = new Result('mailgun', $this->getName());
             $data = $postData;
             $data['to'] = $to_chunk;
             $res = $this->mailgun->sendMessage($this->domain, $data, $message->toString());
             if ($res->http_response_code == 200) {
                 $success[] = $res;
             } else {
                 $result->setResult(Result::FAIL);
                 $failed[] = $res;
             }
             $result->setResponse($res);
             $notification->addResult($result);
         }
         if (count($success) === 0) {
             throw new NotificationFailedException("Sending failed for message {$notification->getSubject()}", $failed);
         }
     }
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification)
 {
     $failedSms = [];
     /** @var Sms $notification */
     $data = $this->getData($notification);
     $tos = $notification->getTo();
     foreach ($tos as $to) {
         $result = new Result('twilio', $this->name, Result::OK);
         $params = $data;
         $params['To'] = $to;
         try {
             $response = $this->twilio->account->messages->create($params);
             $result->setResponse($response);
         } catch (\Exception $e) {
             $result->setResult(Result::FAIL)->setResponse($e);
             $failedSms[] = ['to' => $to, 'error_message' => $e->getMessage()];
         }
         $notification->addResult($result);
     }
     if (count($tos) === count($failedSms)) {
         throw new NotificationFailedException('All the sms failed to be send', ['failed_sms' => $failedSms]);
     }
 }