Example #1
0
 /**
  * @param string $email
  * @param string $name
  */
 public function addBcc($email, $name = null)
 {
     try {
         $this->message->addBcc($email, $name);
     } catch (\Exception $e) {
         throw new MailerException($e->getMessage());
     }
 }
Example #2
0
 public function generateMessage(Reciever $reciever, ContentConfig $contentConfig)
 {
     $message = new Message();
     $message->setFrom($this->sender->getEmail(), $this->sender->getName());
     $message->setBody($contentConfig->getContent($reciever));
     $message->setSubject($contentConfig->getSubject());
     $message->addTo($reciever->getEmail(), $reciever->getFullName());
     $message->addBcc($this->sender->getEmail());
     foreach ($contentConfig->getAttachments() as $attachment) {
         $message->addAttachment($attachment);
     }
     return $message;
 }
Example #3
0
 /**
  * Funkce odesílající emaily s dokumenty lidem.
  * 
  * Maily odesílá podle šablony v presenters/Emaily/dokument.latte
  * 
  * @param \Nette\Database\Table\ActiveRow $dokument Dokument k rozeslání
  * @param \Nette\Database\Table\Selection $lidi Lidé k obmailování
  * @param string $link Link na dokument
  * @return integer Počet odeslaných emailů
  */
 public function sendDokument($dokument, $lidi, $link)
 {
     $mail = new Message();
     $mail->setFrom($this->mailerFromAddress)->setSubject('Nový dokument SVJ Čiklova 647/3');
     $pocet = 0;
     foreach ($lidi as $clovek) {
         $mail->addBcc($clovek->email, $clovek->jmeno);
         $pocet++;
     }
     $latte = new \Latte\Engine();
     $params = array('orderId' => 123, 'link' => $link, 'dokument' => $dokument);
     $mail->setHtmlBody($latte->renderToString(self::templateFolder . 'dokument.latte', $params));
     $mail->addAttachment($dokument->jmeno, file_get_contents(Dokument::DOKUMENTY_FOLDER . $dokument->soubor));
     $this->mailer->send($mail);
     return $pocet;
 }
Example #4
0
 /**
  * @param $to array|string
  * @param $params array
  * @param $template string
  * @return bool|string
  * @throws \Exception
  */
 public function send($to, $params, $template)
 {
     $latte = new \Latte\Engine();
     $mail = new Message();
     $mail->setFrom($this->fromEmail)->setHtmlBody($latte->renderToString($this->templateDir . '/' . $template, $params));
     if (!empty($this->archiveEmail)) {
         $mail->addBcc($this->archiveEmail);
     }
     if (is_string($to)) {
         $mail->addTo($to);
     } elseif (is_array($to) && count($to) > 0) {
         $mail->addTo($to[0]);
         for ($i = 1; $i < count($to); $i++) {
             $mail->addCc($to[$i]);
         }
     } else {
         return "Bad 'to' parameter";
     }
     $this->mailer->send($mail);
     return true;
 }
Example #5
0
 /**
  * @param array $templateParameters
  * @return Nette\Mail\Message
  */
 public function toMessage($templateParameters = [])
 {
     $latte = $this->latteFactory instanceof Nette\Bridges\ApplicationLatte\ILatteFactory ? $this->latteFactory->create() : new Latte\Engine();
     $latte->setLoader(new Latte\Loaders\StringLoader());
     $htmlBody = $latte->renderToString($this->template, $templateParameters);
     $mail = new Nette\Mail\Message();
     $mail->setFrom($this->from);
     $mail->setSubject($this->subject);
     $mail->setHtmlBody($htmlBody);
     if ($this->cc !== NULL) {
         foreach ($this->cc as $cc) {
             $mail->addCc($cc);
         }
     }
     if ($this->bcc !== NULL) {
         foreach ($this->bcc as $bcc) {
             $mail->addBcc($bcc);
         }
     }
     return $mail;
 }
Example #6
0
 /**
  * Here's the magic
  *
  * @param array $recipients
  * @param null $subject
  * @param array $data
  * @throws EmailException
  */
 private function sendEmail($recipients = array(), $subject = '', $data)
 {
     // recipients check
     if (!is_array($recipients)) {
         $recipients = array($recipients);
     }
     if (count($recipients) < 1) {
         throw new EmailException('No subscribers provided. (possibly none in your system)');
     }
     // try sending e-mail
     try {
         $mail = new \Nette\Mail\Message();
         $mail->setFrom($this->senderEmail, $this->senderName)->setSubject($subject);
         foreach ($recipients as $recipient) {
             $mail->addBcc($recipient);
         }
         // set HTML / or plaintext body
         if ($this->htmlEmail == TRUE) {
             $mail->setHTMLBody($this->getEmailTemplate($data));
         } else {
             $mail->setBody($this->getEmailTemplate($data));
         }
         $this->mailer->send($mail);
     } catch (\Exception $e) {
         throw new EmailException($e->getMessage());
     }
 }
 function addBcc($args)
 {
     $this->Message->addBcc($args);
 }
    public function newsletterFormSucceeded(UI\Form $form, $values)
    {
        if (!$values['event_id']) {
            $values['event_id'] = null;
        }
        $this->saveFormValues($values);
        $contacts = array();
        if (!$values['event_id'] && $values['notTest']) {
            foreach ($this->registration as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } elseif ($values['notTest']) {
            foreach ($this->registration->where('event_id = ?', $values['event_id']) as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket->where('event_id = ?', $values['event_id']) as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } else {
            $contacts = [0 => self::EMAIL_OPERATOR];
        }
        $mail = new Nette\Mail\Message();
        $mail->setFrom('Hudební S.O.S. <*****@*****.**>')->setSubject($values['subject'])->setHtmlBody('
				<html><head><title>' . $values['subject'] . '</title></head>
				<body>
				<div style="background-color: rgb(197, 230, 235);color: rgb(0, 117, 117);letter-spacing: 0.3px; margin: auto auto; padding:1em 1em">
				' . $values['text'] . '
				<br /><br />
				</div>
				<hr style="border:0;border-top: 1px solid #DDD;" />
				<center>
				<small>
				<font style="color:silver;font-family:\'Helvetica Neue\', sans-sherif">Pro odhlášení odpovězte na tento email slovy "Prosím odhlásit".</font>
				</small>
				</center>
				</body></html>');
        /** @var Nette\Http\FileUpload $attach */
        foreach ($values['files'] as $attach) {
            $mail->addAttachment($attach->getSanitizedName(), $attach->getContents());
        }
        $counter = 0;
        foreach ($contacts as $contact) {
            $counter++;
            $mail->addBcc($contact);
        }
        $mailer = new Nette\Mail\SendmailMailer();
        try {
            $mailer->send($mail);
            if (!$values['notTest']) {
                $this->flashMessage("Byl odeslán testovací email.", 'success');
            } else {
                $this->flashMessage("Bylo odesláno {$counter} emailů.", 'success');
            }
        } catch (\Exception $e) {
            $this->flashMessage('Při odesílání došlo k chybě. :: ' . $e->getMessage());
        }
        $this->redirect('this');
    }