protected function execute(InputInterface $input, OutputInterface $output) { $message = new \Nette\Mail\Message(); if (!$this->validateEmail($from = trim($input->getOption('from')))) { $output->writeln('<error>Expected valid email address, given "' . $from . '"</error>'); return 1; } $message->setFrom($from); if (!$this->validateEmail($to = trim($input->getArgument('recipient')))) { $output->writeln('<error>Expected valid email address, given "' . $to . '"</error>'); return 1; } $message->addTo($to); $message->setSubject($input->getOption('subject')); $message->setBody($input->getOption('message')); if ($input->getOption('force') && $this->mailer instanceof \Simplement\MailQueue\Mailer) { $this->mailer->send($message, 1, FALSE); } else { $this->mailer->send($message); } }
/** * @param null|string $message * @return \Nette\Mail\Message */ protected function getCopyMail($message = NULL) { $values = $this['form']['_inputs']->getValues(); $mail = new \Nette\Mail\Message(); $mail->setFrom($this->mailformEntity->emails[0], $this->mailformEntity->recipient); $mail->addTo($values['_email'], $values['_name']); $mail->setSubject($this->mailformEntity->subject); $mail->setBody($message ? $message : $this->getCopyMessage()); return $mail; }
/** * Prepare the Message object and return it * @return \Nette\Mail\Message */ protected function prepareMessage() { if (empty($this->subject) && empty($this->textBody) && empty($this->htmlBody)) { throw new \LogicException('Subject and body cannot be empty'); } if (empty($this->to) && empty($this->cc) && empty($this->bcc)) { throw new \LogicException('No recipients were specified for this email'); } $message = new \Nette\Mail\Message(); $message->setSubject($this->subject); if (!empty($this->htmlBody)) { $message->setHtmlBody($this->htmlBody); } if (!empty($this->textBody)) { $message->setBody($this->textBody); } return $message; }
public function sendEmail() { $model = $this->createGridModel(); $items = $model->getItems(); $values = $this['email']->values; foreach ($items as $riesitel) { try { $mail = new \Nette\Mail\Message(); $mail->setFrom('*****@*****.**'); $mail->addTo($riesitel['email']); $mail->setSubject($values['subject']); $mail->setBody($values['body']); $mail->send(); } catch (\Exception $e) { $this['grid']->flashMessage($e->getMessage()); } } $this->redirect('this'); }