Beispiel #1
0
 /**
  * @param NotificationMessageInterface $message
  *
  * @return NotificationInterface
  */
 public function createEmailNotification(NotificationMessageInterface $message)
 {
     $swiftMessage = \Swift_Message::newInstance();
     $from = [$this->settings->get('email.from_address') => $this->settings->get('email.from_name')];
     $swiftMessage->setFrom($from);
     $swiftMessage->setSubject($message->getSubject($this->translator));
     foreach ($message->getUsers() as $user) {
         $swiftMessage->addTo($user->getEmail(), $user->getUsername());
     }
     $format = (string) $this->settings->get('email.format');
     switch ($format) {
         case 'html':
             $swiftMessage->setBody($message->getHtmlContent($this->templating), 'text/html');
             break;
         case 'text':
             $swiftMessage->setBody($message->getTextContent($this->templating), 'text/plain');
             break;
         case 'both':
             $swiftMessage->setBody($message->getHtmlContent($this->templating), 'text/html');
             $swiftMessage->addPart($message->getTextContent($this->templating), 'text/plain');
             break;
         default:
             throw new UnexpectedFormatException($format);
     }
     return new SwiftMailerNotification($swiftMessage);
 }