Example #1
0
 /**
  * Add email to mail message object
  * @param string|array $email
  */
 private function addEmail($email)
 {
     if (is_array($email)) {
         $this->mail->addTo($email[0], $email[1]);
     } else {
         $this->mail->addTo($email);
     }
 }
Example #2
0
 /** @param string $template Kompletná cesta k súboru template */
 public function __construct($template, $user_profiles, $from, $id_registracia)
 {
     parent::__construct();
     $this->mail = new Message();
     $this->template = $template;
     $uf = $user_profiles->find($from);
     $this->from = $uf->users->email;
     $this->email_list = $user_profiles->emailUsersListStr($id_registracia);
     foreach (explode(",", $this->email_list) as $c) {
         $this->mail->addTo(trim($c));
     }
 }
 /**
  * Odesila email pres PHP nastaveni
  * @param string $from
  * @param string | array $to
  * @param string $body
  * @param string $subject
  */
 private function sendMail($from, $to, $body, $subject)
 {
     $mail = new Message();
     $mail->setFrom($from)->setSubject($subject)->setHtmlBody($body);
     if (is_array($to)) {
         foreach ($to as $toItem) {
             $mail->addTo($toItem);
         }
     } else {
         $mail->addTo($to);
     }
     $this->appMailer->send($mail);
 }
Example #4
0
 /**
  * Vytvoří novou zprávu jakožto objekt \Nette\Mail\Message.
  * @see \Nette\Mail\Message
  * @param string|array $to Příjemce zprávy. Víc příjemců může být předáno jako pole.
  * @param string $subject Předmět zprávy.
  * @param string $message Předmět zprávy, nastavuje se přes setHtmlBody, tudíž lze předat výstup šablony.
  */
 public function createMessage($to, $subject, $message)
 {
     $this->message = new \Nette\Mail\Message();
     $this->message->setFrom($this->from);
     if (is_array($to)) {
         foreach ($to as $recipient) {
             $this->message->addTo($recipient);
         }
     } else {
         $this->message->addTo($to);
     }
     $this->message->setSubject($subject);
     $this->message->setHtmlBody($message);
 }
Example #5
0
 /**
  * @param string $user
  * @param string $name
  * @param string $type
  * @param string $action
  * @param mixed[] $templateArgs
  */
 public function send($user, $name, $type, $action, array $templateArgs = array())
 {
     $presenter = $this->createPresenter();
     $request = $this->getRequest($type, $action);
     $response = $presenter->run($request);
     $presenter->template->user = $user;
     $presenter->template->name = $name;
     foreach ($templateArgs as $key => $val) {
         $presenter->template->{$key} = $val;
     }
     if (!$response instanceof TextResponse) {
         throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type));
     }
     try {
         $data = (string) $response->getSource();
     } catch (\Nette\Application\BadRequestException $e) {
         if (Strings::startsWith($e->getMessage(), 'Page not found. Missing template')) {
             throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type));
         }
     }
     $message = new Message();
     $message->setHtmlBody($data);
     $message->setSubject(ucfirst($action));
     $message->setFrom($this->senderEmail, $this->senderName ?: null);
     $message->addTo($user, $name);
     $this->mailer->send($message);
 }
 /**
  * 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);
 }
Example #8
0
 public function onFinish()
 {
     if (!count($this->messages)) {
         return;
     }
     // everything went alright
     $contents = implode(PHP_EOL, $this->messages) . PHP_EOL;
     // Only write the |$contents| to the file when this is not ran as part of a unit test.
     // Ideally we would verify that the write was successful, but there's no good fallback.
     if (!$this->isTest) {
         file_put_contents(self::ERROR_LOG, $contents, FILE_APPEND);
     }
     // Early-return if there are no failures, because there is no need to send an alert message
     // for successful service execution.
     if ($this->failures == 0) {
         return;
     }
     $configuration = Configuration::getInstance();
     // E-mail alerts can be disabled by the configuration, but force-enable them for tests.
     if (!$configuration->get('serviceLog/alerts') && !$this->isTest) {
         return;
     }
     // Compose an e-mail message for sending out an alert message. The recipients of this
     // message are defined in the main configuration file.
     $alert = new Message();
     $alert->setFrom($configuration->get('serviceLog/from'))->setSubject($configuration->get('serviceLog/subject'))->setBody($contents);
     foreach ($configuration->get('serviceLog/recipients') as $recipient) {
         $alert->addTo($recipient);
     }
     $this->mailer->send($alert);
 }
Example #9
0
 /**
  * 发送邮件
  */
 public function mail()
 {
     $mail = new Message();
     $mail->addTo("*****@*****.**");
     $mail->setSubject("hello world");
     $mailer = new \Nette\Mail\SmtpMailer(require BASE_PATH . "/config/mail.php");
     $mailer->send($mail);
 }
Example #10
0
 /**
  * @param string $email
  * @param string $name
  */
 public function addTo($email, $name = null)
 {
     try {
         $this->message->addTo($email, $name);
     } catch (\Exception $e) {
         throw new MailerException($e->getMessage());
     }
 }
Example #11
0
 public function sendKontaktMail($clovekMail, $clovekName, $zprava, $spravci)
 {
     $mail = new Message();
     $mail->setFrom($this->mailerFromAddress)->setSubject('Nová zpráva z konktaktního formuláře webu SVJ Čiklova 647/3')->addReplyTo($clovekMail)->setBody($clovekName . " s emailem " . $clovekMail . " posílá následující dotaz: \n\n" . $zprava);
     foreach ($spravci as $address) {
         $mail->addTo($address);
     }
     $this->mailer->send($mail);
     return 1;
 }
Example #12
0
 /**
  * Process contact form, send message
  * @param Form
  */
 public function processContactForm(Form $form)
 {
     $values = $form->getValues(TRUE);
     $message = new Message();
     $message->addTo('*****@*****.**')->setFrom($values['email'])->setSubject('Zpráva z kontaktního formuláře')->setBody($values['message']);
     $mailer = new SendmailMailer();
     $mailer->send($message);
     $this->flashMessage('Zpráva byla odeslána');
     $this->redirect('this');
 }
Example #13
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 #14
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 #15
0
 /**
  * @param UI\Form $form
  */
 public function processForm(UI\Form $form)
 {
     $values = $form->getValues();
     $template = $this->createTemplate();
     $mail = new Message();
     $template->setFile(__DIR__ . '/../presenters/templates/Emails/contactForm.latte');
     $mail->addTo($this->settings['adminMail'])->setFrom($values['email']);
     $template->title = 'Zpráva z kontaktního formuláře';
     $template->values = $values;
     $mail->setHtmlBody($template);
     $this->mailer->send($mail);
     $this->flashMessage('Zpráva byla odeslána');
     $this->presenter->redirect('Pages:view', ['id' => $this->settings['thanksPage']]);
 }
Example #16
0
 public function actionMailpdf($id)
 {
     $template = $this->createTemplate();
     $template->setFile(dirname(__FILE__) . "/../templates/Faktura/topdf.latte");
     $template->works = $this->praceRepository->findAll()->where(array('FakturaID' => $id));
     $template->faktura = $this->fakturaRepository->findBy(array('FakturaID' => $id))->fetch();
     $template->today = date('d.m.Y');
     $pdf = new PdfResponse($template);
     $savedFile = $pdf->save(dirname(__FILE__) . "/../../temp/");
     $mail = new Nette\Mail\Message();
     $mail->addTo("*****@*****.**");
     $mail->addAttachment($savedFile);
     $mailer = new SendmailMailer();
     $mailer->send($mail);
 }
Example #17
0
 private function sendMail($values)
 {
     $mail = new Message();
     $mail->setSubject('Nová zpráva z kontaktního formuláře');
     $mail->setFrom($values['email'], $values['name']);
     $mail->addTo('*****@*****.**', 'Feedback form');
     $template = $this->createTemplate();
     $template->setFile(__DIR__ . '/templates/Mail.phtml');
     $template->name = $values['name'];
     $template->email = $values['email'];
     $template->text = $values['text'];
     $mail->setHtmlBody($template);
     $mailer = new SendmailMailer();
     $mailer->send($mail);
 }
Example #18
0
 /**
  * Send mail by calling a single method - as you often don't need more...
  *
  * @param string|array $recipients
  * @param string $subject
  * @param string $body
  * @param string|NULL $sender
  * @return void
  * @throws SendException
  */
 public function sendMail($recipients, $subject, $body, $sender = NULL)
 {
     $mail = new Message();
     if ($sender !== NULL) {
         $mail->setFrom($sender);
     }
     $mail->setSubject($subject)->setBody($body);
     if (!is_array($recipients)) {
         $recipients = [$recipients];
     }
     foreach ($recipients as $rcpt) {
         $mail->addTo($rcpt);
     }
     $mailer = $this->mailer;
     $mailer->send($mail);
 }
 /**
  * @param array $receivers
  * @param string $subject
  * @param string $messageText
  * @param string $attachedFile
  * @return ResultObject
  */
 private function sendMail(array $receivers, $subject, $messageText, $attachedFile = null)
 {
     $result = new ResultObject();
     $message = new Message();
     $message->setFrom('Výčetkový systém <' . $this->systemEmail . '>')->setSubject($subject)->setBody($messageText);
     foreach ($receivers as $receiverEmail) {
         $message->addTo($receiverEmail);
     }
     if ($attachedFile !== null and file_exists($attachedFile)) {
         $message->addAttachment($attachedFile);
     }
     try {
         $this->mailer->send($message);
     } catch (SendException $s) {
         $this->logger->addError(sprintf('Backup file sending\'s failed. %s', $s));
         $result->addError('Zálohu se nepodařilo odeslat', 'error');
     }
     return $result;
 }
Example #20
0
 /**
  * @param string $view email template
  * @param User $user
  * @param NULL|array $args template variables
  *
  * @throws Exception from Latte\Engine
  * @throws SmtpException from Mailer
  */
 public function send($view, User $user, array $args = [])
 {
     if ($this->orm->unsubscribes->getByEmail($user->email)) {
         // Last line of defense. Make sure unsubscribed users
         // really dont receive any email. This should however
         // be handled before the task is queued.
         $this->logger->addAlert("Email to '{$user->email}' not send, user unsubscribed. Find out why it was queued");
         return;
     }
     $msg = new Message();
     $msg->setFrom('Khanova škola <*****@*****.**>');
     $msg->addReplyTo('Markéta Matějíčková <*****@*****.**>');
     $msg->addTo($user->email, $user->name);
     $token = Unsubscribe::createFromUser($user);
     $token->emailType = $view;
     $this->orm->tokens->attach($token);
     $this->orm->flush();
     $args['recipient'] = $user;
     $args['email'] = $msg;
     $args['unsubscribe'] = (object) ['token' => $token, 'code' => $token->getUnsafe()];
     $args['baseUrl'] = rtrim($this->baseUrl, '/');
     $latte = new Engine();
     /** @var Presenters\Token $presenter */
     $presenter = $this->factory->createPresenter('Token');
     $presenter->autoCanonicalize = FALSE;
     $ref = new \ReflectionProperty(Presenter::class, 'globalParams');
     $ref->setAccessible(TRUE);
     $ref->setValue($presenter, []);
     $latte->addFilter('token', function (Token $token, $unsafe) use($presenter, $view) {
         return $presenter->link('//Token:', ['token' => $token->toString($unsafe), 'utm_campaign' => "email-{$view}"]);
     });
     $latte->addFilter('vocative', function ($phrase) {
         return $this->inflection->inflect($phrase, 5);
     });
     $template = $latte->renderToString($this->getTemplate($view), $args);
     $msg->setHtmlBody($template);
     $this->mailer->send($msg);
     $this->logger->addInfo('Email send', ['view' => $view, 'email' => $user->email]);
 }
Example #21
0
 /**
  * Notify an humean on email
  *
  * @param $subject
  * @param $message
  * @param array $data
  */
 public function mailNotify($subject, $message, $data = array())
 {
     $table = "<table>\n";
     foreach ($data as $key => $value) {
         try {
             $value = (string) $value;
         } catch (\Exception $e) {
             $value = "<i>hodnota není text</i>";
         }
         $table .= "<tr><th>{$key}</th><td>{$value}</td></tr>\n";
     }
     $table .= "</table>\n";
     $message = "<p>{$message}</p>\n\n";
     if (count($data)) {
         $message .= "<p>Tabulka dat:</p>\n{$table}";
     }
     $mail = new Nette\Mail\Message();
     $mail->setSubject($subject);
     $mail->setHtmlBody($message);
     $mail->addTo(self::NOTIFY_EMAIL_ADDRESS);
     $mailer = new Nette\Mail\SendmailMailer();
     $mailer->send($mail);
 }
Example #22
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();
 }
 function addTo($args)
 {
     $this->Message->addTo($args);
 }
Example #24
0
 /**
  * Funkce pro odeslání potvrzovacího e-mailu po registraci uživatele
  * @param User $user
  */
 public function sendRegistrationMail(User $user)
 {
     $mail = new Message();
     $mail->setFrom('*****@*****.**');
     //TODO tady by měla bát nějaká rozumná adresa
     $mail->addTo($user->email);
     $mail->setSubject('Registrace na webu...');
     $mail->setHtmlBody('<p>Byli jste úspěšně zaregistrováni, pro přihlášení využijte e-mail <strong>' . $user->email . '</strong></p>');
     $mailer = new SendmailMailer();
     $mailer->send($mail);
 }
Example #25
0
    $offer->setOrderUntil($body->order_until);
    $offer->save();
    // Load user
    $user = User::getById($body->user);
    // Load restaurant
    $restaurant = Restaurant::getById($body->restaurant);
    // Send Mail
    $mailSubscriptions = MailSubscription::getAll();
    $receivers = array();
    foreach ($mailSubscriptions as $mailSubscription) {
        $receivers[] = User::getById($mailSubscription->getUser());
    }
    $mail = new Message();
    $mail->setFrom('Mittagessen Plattform <*****@*****.**>')->setSubject($user->getName() . ' holt Essen bei ' . $restaurant->getName())->setBody("Wenn du auch was willst, schaue auf " . $config['platform_url'] . "/app/#/offers/" . $offer->getId());
    foreach ($receivers as $receiver) {
        $mail->addTo($receiver->getEmail());
    }
    switch ($config['mail_method']) {
        case "sendmail":
            $mailer = new SendmailMailer();
            break;
        case "smtp":
            $mailer = new \Nette\Mail\SmtpMailer($config['smtpmail_settings']);
    }
    $mailer->send($mail);
    print "<html><pre>";
    print_r($receivers);
});
$app->get('/user/:id', function ($id) {
    outputJSON(User::getById($id));
});
Example #26
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;
 }
Example #27
0
 /**
  * Adds email recipient
  *
  * @param string $email
  * @param string $name
  *
  * @return Message
  */
 public function addTo($email, $name = NULL)
 {
     $this->to = array_merge($this->to, $this->formatEmail($email, $name));
     parent::addTo($email, $name);
     return $this;
 }
Example #28
0
 public function compose(Nette\Mail\Message $message, $params = NULL)
 {
     $message->setFrom("{$params['name']} <{$params['from']}>");
     $message->addTo($this->mails['recipient']);
 }
 /**
  * Send request for connecting an account with group member
  *
  * @param string $username              Account username
  * @param string $name                  Member's name
  * @param string $surname               Member's surname
  */
 private function sendConnectionMail($username, $name, $surname)
 {
     $message = new Message();
     $recipient = $this->context->parameters['supportMail'];
     $message->addTo($recipient);
     $template = $this->createTemplate();
     $template->setFile(__DIR__ . '/../templates/emails/connect.latte');
     $template->title = '27skauti.cz - Propojení účtů';
     $template->username = $username;
     $template->name = $name;
     $template->surname = $surname;
     $message->setHtmlBody($template);
     $mailer = new \Nette\Mail\SendmailMailer();
     $mailer->send($message);
 }
 /**
  * Processes Form for Opting in
  *
  * @param \Nette\Application\UI\Form $form
  */
 public function optInFormSucceeded(\Nette\Application\UI\Form $form)
 {
     //Sets the information
     $values = $form->getValues(TRUE);
     try {
         $message = new Message();
         $message->addTo($this->context->parameters['contactMail'])->setFrom($values['mail']);
         //Templating
         $template = $this->createTemplate();
         $template->setFile(__DIR__ . '/../templates/emails/optInTemplate.latte');
         $template->title = '27skauti.cz - Nezávazná příhláška';
         $template->values = $values;
         $message->setHtmlBody($template);
         //Sending
         $mailer = new \Nette\Mail\SendmailMailer();
         $mailer->send($message);
         $this->flashMessage('Přihláška byla odeslána');
         $this->redirect('default');
     } catch (\Nette\InvalidStateException $e) {
         $this->flashMessage('Přihlášku se nepodařilo odeslat. Zkuste to prosím později');
     }
 }