/**
  * Callback for ForgottenPasswordForm onSuccess event.
  * @param Form      $form
  * @param ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     $user = $this->userManager->findByEmail($values->email);
     if (!$user) {
         $form->addError('No user with given email found');
         return;
     }
     $password = Nette\Utils\Random::generate(10);
     $this->userManager->setNewPassword($user->id, $password);
     try {
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $mail = new Nette\Mail\Message();
         $mail->setFrom('*****@*****.**', 'Notejamapp');
         $mail->addTo($user->email);
         $mail->setSubject('New notejam password');
         $mail->setBody(sprintf('Your new password: %s', $password));
         $this->mailer->send($mail);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, Debugger::EXCEPTION);
         $form->addError('Could not send email with new password');
     }
 }
 /**
  * Callback method, that is called once form is successfully submitted, without validation errors.
  *
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!($user = $this->userRepository->findOneBy(['email' => $values->email]))) {
         $form['email']->addError("User with given email doesn't exist");
         return;
     }
     // this is not a very secure way of getting new password
     // but it's the same way the symfony app is doing it...
     $newPassword = $user->generateRandomPassword();
     $this->em->flush();
     try {
         $message = new Nette\Mail\Message();
         $message->setSubject('Notejam password');
         $message->setFrom('*****@*****.**');
         $message->addTo($user->getEmail());
         // !!! Never send passwords through email !!!
         // This is only for demonstration purposes of Notejam.
         // Ideally, you can create a unique link where user can change his password
         // himself for limited amount of time, and then send the link.
         $message->setBody("Your new password is {$newPassword}");
         $this->mailer->send($message);
     } catch (Nette\Mail\SendException $e) {
         Debugger::log($e, 'email');
         $form->addError('Could not send email with new password');
     }
     $this->onSuccess($this);
 }
Esempio n. 3
0
 /**
  * @param string $body
  */
 public function setBody($body)
 {
     try {
         $this->message->setBody($body);
     } catch (\Exception $e) {
         throw new MailerException($e->getMessage());
     }
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 public function bindMessage(Mail\Message $message, array $data = [], $assetsDir = NULL)
 {
     if ($this->plain) {
         if ($this->plain instanceof UI\ITemplate) {
             $this->bindNetteTemplate($this->plain, $data);
         }
         $message->setBody($this->plain);
     }
     if ($this->html) {
         if ($this->html instanceof UI\ITemplate) {
             $this->bindNetteTemplate($this->html, $data);
         }
         $message->setHtmlBody($this->html, $assetsDir);
     }
 }
Esempio n. 6
0
 /**
  * Handle message delivery.
  *
  * @return bool
  */
 public static function sendMail()
 {
     // Allow support for legacy argument style or new style.
     $args = func_get_args();
     if (func_num_args() == 1) {
         $options = $args[0];
     } else {
         $options = array_merge(array('to' => $args[0], 'subject' => $args[1], 'message' => $args[2], 'reply_to' => $args[3], 'delivery_date' => $args[4]), $args[5]);
     }
     $di = \Phalcon\Di::getDefault();
     $config = $di->get('config');
     $mail_config = $config->application->mail->toArray();
     // Do not deliver mail on development environments.
     if (DF_APPLICATION_ENV == "development" && !defined('DF_FORCE_EMAIL')) {
         $email_to = $mail_config['from_addr'];
         if (!empty($email_to)) {
             $options['to'] = $email_to;
         } else {
             return false;
         }
     }
     if (isset($mail_config['use_smtp']) && $mail_config['use_smtp']) {
         $smtp_config = $config->apis->smtp->toArray();
         $smtp_config['host'] = $smtp_config['server'];
         unset($smtp_config['server']);
         $transport = new SmtpMailer($smtp_config);
     } else {
         $transport = new SendmailMailer();
     }
     if (!is_array($options['to'])) {
         $options['to'] = array($options['to']);
     } else {
         $options['to'] = array_unique($options['to']);
     }
     foreach ((array) $options['to'] as $mail_to_addr) {
         if (empty($mail_to_addr)) {
             continue;
         }
         $mail_to_addr = str_replace('mailto:', '', $mail_to_addr);
         $mail = new Message();
         $mail->setSubject($options['subject']);
         $from_addr = isset($options['from']) ? $options['from'] : $mail_config['from_addr'];
         $from_name = isset($options['from_name']) ? $options['from_name'] : $mail_config['from_name'];
         $mail->setFrom($from_addr, $from_name);
         if (isset($mail_config['bounce_addr'])) {
             $mail->setReturnPath($mail_config['bounce_addr']);
         }
         /*
         // Include a specific "Direct replies to" header if specified.
         if ($options['reply_to'] && $validator->isValid($options['reply_to']))
             $mail->setReplyTo($options['reply_to']);
         else if (isset($mail_config['reply_to']) && $mail_config['reply_to'])
             $mail->setReplyTo($mail_config['reply_to']);
         */
         // Change the type of the e-mail's body if specified in the options.
         if (isset($options['text_only']) && $options['text_only']) {
             $mail->setBody(strip_tags($options['message']));
         } else {
             $mail->setHtmlBody($options['message'], false);
         }
         // Add attachment if specified in options.
         if (isset($options['attachments'])) {
             foreach ((array) $options['attachments'] as $attachment) {
                 $mail->addAttachment($attachment);
             }
         }
         /*
         // Modify the mail type if specified.
         if (isset($options['type']))
             $mail->setType($options['type']);
         */
         // Catch invalid e-mails.
         try {
             $mail->addTo($mail_to_addr);
         } catch (\Nette\Utils\AssertionException $e) {
             continue;
         }
         $transport->send($mail);
     }
     return true;
 }
Esempio n. 7
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());
     }
 }
Esempio n. 8
0
 public function sendTestEmailSmtp($from, $to, $settings)
 {
     $mailer = new SmtpMailer($settings);
     $message = new Message();
     $message->setFrom($from);
     $message->addTo($to);
     $message->setBody('Tatami mail test');
     $message->setMailer($mailer);
     $message->send();
 }