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; }
function send(\xepan\communication\Model_Communication_EmailSetting $email_setting, $mailer = null) { $this['status'] = 'Outbox'; $this['direction'] = 'Out'; $this['mailbox'] = $email_setting['email_username'] . '#SENT'; $this['description'] = $this['description'] . $email_setting['signature']; if (!$this['to_id']) { $this->findContact('to'); } $this['communication_channel_id'] = $email_setting->id; if (!$this->app->getConfig('test_mode', false)) { try { $mail = new \Nette\Mail\Message(); $mail->setFrom($this['from_raw']['email'], $this['from_raw']['name'] ?: null); $return_path = $email_setting['return_path']; if (!$return_path) { $return_path = $this['from_raw']['email']; } $mail->setReturnPath($return_path); foreach ($this['to_raw'] as $to) { $mail->addTo(trim($to['email']), $to['name'] ?: null); } if ($this['cc_raw']) { foreach ($this['cc_raw'] as $cc) { $mail->addCC(trim($cc['email']), $cc['name'] ?: null); } } if ($this['bcc_raw']) { foreach ($this['bcc_raw'] as $bcc) { $mail->addBcc(trim($bcc['email']), $bcc['name'] ?: null); } } foreach ($this->getAttachments() as $attach) { $mail->addAttachment($_SERVER["DOCUMENT_ROOT"] . $attach); } $mail->setSubject($this['title'])->setHTMLBody($this['description'], $this->app->pathfinder->base_location->base_path); if (!$mailer) { if (isset($this->app->mailer)) { $mailer = $this->app->mailer; } else { $mailer = new \Nette\Mail\SmtpMailer(array('host' => $email_setting['email_host'], 'username' => $email_setting['email_username'], 'password' => $email_setting['email_password'], 'secure' => $email_setting['encryption'], 'persistent' => true)); $this->app->mailer = $mailer; } } $mailer->send($mail); $email_setting['last_emailed_at'] = $this->app->now; $email_setting['email_sent_in_this_minute'] = $email_setting['email_sent_in_this_minute'] + 1; $email_setting->save(); } catch (\Exception $e) { $this->save(); throw $e; } } if ($this->app->getConfig('test_mode', false)) { // echo "setting last_emailed_at on ". $email_setting['name']. ' as '. $this->app->now . '<br/>'; $email_setting['last_emailed_at'] = $this->app->now; $email_setting['email_sent_in_this_minute'] = $email_setting['email_sent_in_this_minute'] + 1; $email_setting->save(); } $this['status'] = 'Sent'; $this->save(); }
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'); }