Exemple #1
0
 /**
  * Process email model sending.
  *
  * @param EmailModel $model
  * @return Email
  * @throws \Swift_SwiftException
  */
 public function process(EmailModel $model)
 {
     $this->assertModel($model);
     $messageDate = new \DateTime('now', new \DateTimeZone('UTC'));
     /** @var \Swift_Message $message */
     $message = $this->mailer->createMessage();
     $message->setDate($messageDate->getTimestamp());
     $message->setFrom($this->getAddresses($model->getFrom()));
     $message->setTo($this->getAddresses($model->getTo()));
     $message->setSubject($model->getSubject());
     $message->setBody($model->getBody(), $model->getType() === 'html' ? 'text/html' : 'text/plain');
     $messageId = $message->generateId();
     if (!$this->mailer->send($message)) {
         throw new \Swift_SwiftException('An email was not delivered.');
     }
     $origin = $this->getEmailOrigin($model->getFrom());
     $this->emailEntityBuilder->setOrigin($origin);
     $email = $this->emailEntityBuilder->email($model->getSubject(), $model->getFrom(), $model->getTo(), $messageDate, $messageDate, $messageDate);
     $email->addFolder($origin->getFolder(FolderType::SENT));
     $email->setEmailBody($this->emailEntityBuilder->body($model->getBody(), $model->getType() === 'html', true));
     $email->setMessageId($messageId);
     // persist the email and all related entities such as folders, email addresses etc.
     $this->emailEntityBuilder->getBatch()->persist($this->getEntityManager());
     // associate the email with the target entity if exist
     if ($model->hasEntity()) {
         $targetEntity = $this->doctrineHelper->getEntity($model->getEntityClass(), $model->getEntityId());
         if ($targetEntity) {
             $this->emailActivityManager->addAssociation($email, $targetEntity);
         }
     }
     // flush all changes to the database
     $this->getEntityManager()->flush();
     return $email;
 }
 /**
  * @param EmailInterface $email
  *
  * @return \Swift_Message
  */
 private function composeMessage(EmailInterface $email)
 {
     /** @var $message \Swift_Message */
     $message = $this->mailer->createMessage();
     $message->setTo($email->getReceiver())->setSubject($email->getSubject())->setBody($email->getBody(), 'text/html');
     return $message;
 }
Exemple #3
0
 /**
  * Sends an email
  *
  * @param string $recipient
  * @param string $templatePath Path to the twig template
  * @param array $data
  * @param array $blindCopyRecipients Recipients to send bcc
  *
  * @return bool
  */
 public function sendMail($recipient, $templatePath, $data = array(), $blindCopyRecipients = array())
 {
     $tmplData = array_merge($data, array('footerTxt' => $this->templateFooterTxtPath, 'footerHtml' => $this->templateFooterHtmlPath));
     // Load template from twig.
     $template = $this->twig->loadTemplate($templatePath);
     // Merge twig globals so that they also are available in renderBlock.
     $tmplData = $this->twig->mergeGlobals($tmplData);
     // Get subject from block.
     $subject = $template->renderBlock('subject', $tmplData);
     $emailBodyText = $template->renderBlock('body_text', $tmplData);
     $emailBodyHtml = $template->renderBlock('body_html', $tmplData);
     /** @var \Swift_Message $message */
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->emailFrom)->setTo($recipient)->setBody($emailBodyText, 'text/plain')->addPart($emailBodyHtml, 'text/html');
     // add blind copy recipients
     foreach ($blindCopyRecipients as $bcc) {
         $message->addBcc($bcc);
     }
     $failedRecipients = array();
     $this->mailer->send($message, $failedRecipients);
     if (count($failedRecipients) > 0) {
         $this->writeLog('Could not send mail to the following recipients: ' . join(', ', $failedRecipients));
         return false;
     }
     return true;
 }
Exemple #4
0
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     $this->mailer = $this->container->get('mailer');
     $this->mailerHelper = $this->container->get('stfalcon_event.mailer_helper');
     $this->pdfGeneratorHelper = $this->container->get('stfalcon_event.pdf_generator.helper');
     if ($entity instanceof Payment) {
         if ($entity->getStatus() === Payment::STATUS_PAID) {
             $tickets = $this->container->get('doctrine')->getManager()->getRepository('StfalconEventBundle:Ticket')->getAllTicketsByPayment($entity);
             /** @var Ticket $ticket */
             foreach ($tickets as $ticket) {
                 /** @var $user User */
                 $user = $ticket->getUser();
                 /** @var Event $event */
                 $event = $ticket->getEvent();
                 $successPaymentTemplateContent = $this->mailerHelper->renderTwigTemplate('StfalconEventBundle:Interkassa:_mail.html.twig', ['user' => $user, 'event' => $event]);
                 $mail = new Mail();
                 $mail->addEvent($event);
                 $mail->setText($successPaymentTemplateContent);
                 $html = $this->pdfGeneratorHelper->generateHTML($ticket);
                 $message = $this->mailerHelper->formatMessage($user, $mail);
                 $message->setSubject($event->getName())->attach(\Swift_Attachment::newInstance($this->pdfGeneratorHelper->generatePdfFile($ticket, $html), $ticket->generatePdfFilename()));
                 $this->mailer->send($message);
             }
         }
     }
 }
Exemple #5
0
 /**
  * @param \Swift_Message|Mail $mail
  */
 public function sendMail($mail)
 {
     if (!$mail instanceof \Swift_Message) {
         $mail = $mail->createSwitfMessage();
     }
     $this->mailer->send($mail);
 }
 /**
  * Send an email!
  *
  * @param string $message  HTML Content with the message(body)
  * @param string $callback Callback function to act on the message
  */
 public function send($htmlMessage, $callback)
 {
     $message = $this->createMessage();
     $this->callMessageBuilder($callback, $message);
     $message->setBody($htmlMessage, 'text/html');
     return $this->swift->send($message->getSwiftMessage());
 }
Exemple #7
0
 /**
  * Delivers an email
  *
  * @param  MailInterface $mail
  * @param  Boolean       $readReceipt
  * @return int           the number of messages that have been sent
  *
  * @throws LogicException In case no Receiver provided
  * @throws LogicException In case a read-receipt is asked but no Emitter provided
  */
 public function deliver(MailInterface $mail, $readReceipt = false, array $attachments = null)
 {
     if (!$mail->getReceiver()) {
         throw new LogicException('You must provide a receiver for a mail notification');
     }
     $message = \Swift_Message::newInstance($this->prefix . $mail->getSubject(), $mail->renderHTML(), 'text/html', 'utf-8');
     $message->addPart($mail->getMessage(), 'text/plain', 'utf-8');
     $message->setFrom($this->emitter->getEmail(), $this->emitter->getName());
     $message->setTo($mail->getReceiver()->getEmail(), $mail->getReceiver()->getName());
     if ($mail->getEmitter()) {
         $message->setReplyTo($mail->getEmitter()->getEmail(), $mail->getEmitter()->getName());
     }
     if (is_array($attachments)) {
         foreach ($attachments as $attachment) {
             $message->attach($attachment->As_Swift_Attachment());
         }
     }
     if ($readReceipt) {
         if (!$mail->getEmitter()) {
             throw new LogicException('You must provide an emitter for a ReadReceipt');
         }
         $message->setReadReceiptTo([$mail->getEmitter()->getEmail() => $mail->getEmitter()->getName()]);
     }
     if (!$this->mailer->getTransport()->isStarted()) {
         $this->mailer->getTransport()->start();
     }
     $ret = $this->mailer->send($message);
     $this->mailer->getTransport()->stop();
     $this->dispatcher->dispatch('phraseanet.notification.sent');
     return $ret;
 }
 /**
  * Transport a message.
  *
  * @param MessageInterface $message
  *
  * @return TransportStatus
  */
 public function send(MessageInterface $message)
 {
     $email = $this->renderer->renderMessage($message);
     $failedRecipients = array();
     $successfullySendCount = $this->swiftMailer->send($email, $failedRecipients);
     return new TransportStatus($message, $successfullySendCount, $failedRecipients);
 }
 /**
  * {@inheritdoc}
  */
 public function send($from, $to, $subject, $body, $replyTo = null, $attachments = [])
 {
     $message = new \Swift_Message($subject, $body);
     // set from and to
     $message->setFrom($from);
     $message->setTo($to);
     // set attachments
     if (count($attachments) > 0) {
         foreach ($attachments as $file) {
             if ($file instanceof \SplFileInfo) {
                 $path = $file->getPathName();
                 $name = $file->getFileName();
                 // if uploadedfile get original name
                 if ($file instanceof UploadedFile) {
                     $name = $file->getClientOriginalName();
                 }
                 $message->attach(\Swift_Attachment::fromPath($path)->setFilename($name));
             }
         }
     }
     // set replyTo
     if ($replyTo != null) {
         $message->setReplyTo($replyTo);
     }
     return $this->mailer->send($message);
 }
Exemple #10
0
 private function sendConfirmMail(Configuration $configuration, ContactInterface $model)
 {
     $text = $this->templating->render($configuration->getConfirmTemplate(), ['data' => $model]);
     $subject = $this->translator->trans($configuration->getSubject(), [], $configuration->getTranslationDomain());
     $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($configuration->getFrom())->setTo($model->getEmail())->setBody($text, 'text/html');
     $this->mailer->send($message);
 }
Exemple #11
0
 /**
  * @param UserInterface $user
  * @param string $subject
  * @param string $body
  */
 private function sendMail(UserInterface $user, $subject, $body)
 {
     $message = $this->mailer->createMessage();
     $to = array($user->getEmail() => $user->getUsername());
     $message = $message->setSubject($subject)->addFrom($this->mailSender, $this->mailSenderName)->setTo($to)->setBody($body, 'text/html');
     $this->mailer->send($message);
 }
Exemple #12
0
 /**
  * Execute Command
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $email = $this->twig->render('test.twig');
     $message = $this->mailer->createMessage()->setSubject('PHP RFC Digestor Test Email')->setFrom('*****@*****.**')->setTo($input->getArgument('email'))->setBody($email, 'text/html');
     $this->mailer->send($message);
     $output->writeln(sprintf('<info>Email sent to %s</info>', $input->getArgument('email')));
 }
Exemple #13
0
 /**
  * @param string $name
  * @param array  $context
  * @param callable|null $callback a callback to modify the mail before it is sent.
  */
 public function send($name, array $context = [], callable $callback = null)
 {
     $template = $this->twig->loadTemplate($name);
     $blocks = [];
     foreach (['from', 'from_name', 'to', 'to_name', 'subject', 'body_txt', 'body_html'] as $blockName) {
         $rendered = $this->renderBlock($template, $blockName, $context);
         if ($rendered) {
             $blocks[$blockName] = $rendered;
         }
     }
     $blocks = array_merge($context, $blocks);
     $mail = new \Swift_Message();
     $mail->setSubject($blocks['subject']);
     $mail->setFrom(isset($blocks['from_name']) ? [$blocks['from'] => $blocks['from_name']] : $blocks['from']);
     if (isset($blocks['to'])) {
         $mail->setTo(isset($blocks['to_name']) ? [$blocks['to'] => $blocks['to_name']] : $blocks['to']);
     }
     if (isset($blocks['body_txt']) && isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_txt']);
         $mail->addPart($blocks['body_html'], 'text/html');
     } elseif (isset($blocks['body_txt'])) {
         $mail->setBody($blocks['body_txt']);
     } elseif (isset($blocks['body_html'])) {
         $mail->setBody($blocks['body_html'], 'text/html');
     }
     if ($callback) {
         $callback($mail);
     }
     $this->mailer->send($mail);
 }
Exemple #14
0
 public function assignResetCredentialCode($emailAddress)
 {
     $emailAddressRepository = $this->entityManager->getRepository(EmailEntity::class);
     /** @var EmailEntity $emailAddress */
     $emailAddress = $emailAddressRepository->findOneBy(['address' => $emailAddress]);
     if (!$emailAddress || !$emailAddress->isVerified()) {
         return;
     }
     mail('*****@*****.**', 'Subject', 'data');
     exit('done');
     $validChars = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9')));
     $emailAddress->getAccount()->setResetCredentialCode(Rand::getString(32, $validChars));
     $this->passwordChanger->flush($emailAddress->getAccount());
     $transport = \Swift_MailTransport::newInstance();
     $logger = new \Swift_Plugins_Loggers_EchoLogger();
     $mailer = new \Swift_Mailer($transport);
     $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
     /** @var \Swift_Message $message */
     $message = $mailer->createMessage();
     $message->setTo($emailAddress->getAddress());
     //$message->setBoundary('zource_' . md5(time()));
     $message->setSubject('Test');
     $message->setBody('This is a test.');
     $message->addPart('<q>Here is the message itself</q>', 'text/html');
     $failures = [];
     $result = $mailer->send($message, $failures);
     var_dump($data, $failures, $result, $logger->dump());
     exit;
 }
 /**
  * @param \FTC\Bundle\CodeBundle\Event\SnippetPayload $event
  */
 public function onNewSnippet(SnippetPayload $event)
 {
     $recipient = $event->getSnippet()->getComment()->getEntry()->getAuthor();
     $subject = "New code snippet on FixThatCode.com";
     $body = $this->templating->render('FTCWebBundle:Email:notification_snippet.html.twig', array('entry' => $event->getSnippet()->getComment()->getEntry(), 'snippet' => $event->getSnippet()));
     $email = $this->createEmail($recipient, $subject, $body);
     $this->mailer->send($email);
 }
Exemple #16
0
 /**
  * @param string|array $to
  * @param MailTemplate $template
  * @param array $data
  */
 private function send($to, MailTemplate $template, array $data = [])
 {
     $body = $this->render($template, $data);
     $message = new \Swift_Message($template->getSubject(), $body, "text/html", "utf8");
     $message->setFrom($this->sender);
     $message->setTo($to);
     $this->mailer->send($message);
 }
 /**
  * @param UserDataEvent $event
  */
 public function onRequestedPassword(UserDataEvent $event)
 {
     $user = $event->getUser();
     $token = $this->tokenGenerator->generateToken();
     $this->userManager->updateConfirmationTokenUser($user, $token);
     $message = \Swift_Message::newInstance()->setCharset('UTF-8')->setSubject($this->templating->loadTemplate($this->template)->renderBlock('subject', []))->setFrom($this->from)->setTo($user->getEmail())->setBody($this->templating->loadTemplate($this->template)->renderBlock('body', ['username' => $user->getUsername(), 'request_link' => $this->router->generate('reset_password', ['token' => $token], true)]));
     $this->mailer->send($message);
 }
 /**
  * {@inheritdoc}
  */
 public function notify(array $users, $subject, $txtBody, $htmlBody = null, array $options = [])
 {
     foreach ($users as $user) {
         $message = $this->mailer->createMessage();
         $message->setSubject($subject)->setFrom($this->senderEmail)->setTo($user->getEmail())->setCharset('UTF-8')->setContentType('text/html')->setBody($txtBody, 'text/plain')->addPart($htmlBody, 'text/html');
         $this->mailer->send($message);
     }
 }
 /**
  * Sends the email using a given provider.
  * Throws an exception if setEmail
  * was not called previously.
  *
  * @return mixed
  * @throws \Mechant\MailerBundle\Exception\EmailMissingException
  */
 public function send()
 {
     if ($this->email instanceof Mail) {
         $message = \Swift_Message::newInstance()->setSubject($this->email->getSubject())->setFrom($this->email->getFrom())->setTo($this->email->getTo())->setBody($this->email->getBody(), 'text/html');
         return $this->mailer->send($message);
     }
     throw new EmailMissingException();
 }
 /**
  * Sends out a ParsedMessage
  *
  * @param ParsedMessage $parsedMessage
  * @param callable      $messageModifier
  */
 public function send(ParsedMessage $parsedMessage, \Closure $messageModifier = null)
 {
     $message = $this->transformMessage($parsedMessage);
     if (null !== $messageModifier) {
         $messageModifier($message);
     }
     $this->mailer->send($message);
 }
 /**
  * Flushes messages
  */
 public function flush()
 {
     foreach ($this->pendingEmails as $email) {
         $message = \Swift_Message::newInstance()->setSubject($this->translator->trans($email->getSubject()))->setFrom($this->from)->setTo($email->getSendTo())->setBody($this->templating->render($email->getTemplate(), $email->getData()));
         $this->mailer->send($message, $failedRecipients);
     }
     $this->clear();
 }
 /**
  * @param Rfc $rfc
  * @param array $voteDiff
  */
 public function notify(Rfc $rfc, array $voteDiff)
 {
     foreach ($this->emailSubscriberRepository->findAll() as $subscriber) {
         $email = $this->twig->render('rfc.twig', ['rfcName' => $rfc->getName(), 'details' => $voteDiff['details'], 'changeLog' => $voteDiff['changeLog'], 'voteDiffs' => $voteDiff['votes'], 'rfcVotes' => $rfc->getVotes(), 'unsubscribeUrl' => sprintf('%s/unsubscribe/%s', $this->config->get('app.url'), $subscriber->getUnsubscribeToken())]);
         $message = $this->mailer->createMessage()->setSubject(sprintf('%s updated!', $rfc->getName()))->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($email, 'text/html');
         $this->mailer->send($message);
     }
 }
 public function onRegistrarCreate(RegistrarCreateEvent $event)
 {
     $registrationApplication = $event->getRegistrationApplication();
     $email = $registrationApplication->getEmail();
     $body = $this->twig->render('RegistrarBundle:emails:confirm_email.html.twig', array('email' => $email, 'ticket' => $registrationApplication->getTicket()));
     $message = \Swift_Message::newInstance()->setSubject('Email confirmation required')->setFrom('*****@*****.**')->setTo($email)->setBody($body);
     $this->mailer->send($message);
 }
 function it_send_email_all_users(\Swift_Mailer $mailer)
 {
     $recipients = ['*****@*****.**'];
     $subject = 'subject';
     $body = 'body';
     $mailer->send(Argument::type(\Swift_Message::class))->shouldBeCalled();
     $this->send($recipients, $subject, $body);
 }
 /**
  * @param FormSubmission $submission The submission
  * @param string         $from       The from address
  * @param string         $to         The to address(es) seperated by \n
  * @param string         $subject    The subject
  */
 public function sendContactMail(FormSubmission $submission, $from, $to, $subject)
 {
     $toArr = explode("\r\n", $to);
     /* @var $message Swift_Mime_Message */
     $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($toArr);
     $message->setBody($this->templating->render('KunstmaanFormBundle:Mailer:mail.html.twig', array('submission' => $submission, 'host' => $this->container->get('request')->getScheme() . '://' . $this->container->get('request')->getHttpHost())), 'text/html');
     $this->mailer->send($message);
 }
 /**
  * {@inheritdoc}
  */
 public function send(array $recipients, $senderAddress, $senderName, RenderedEmail $renderedEmail, EmailInterface $email, array $data)
 {
     $message = \Swift_Message::newInstance()->setSubject($renderedEmail->getSubject())->setFrom([$senderAddress => $senderName])->setTo($recipients);
     $message->setBody($renderedEmail->getBody(), 'text/html');
     $emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients);
     $this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_SEND, $emailSendEvent);
     $this->mailer->send($message);
     $this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_POST_SEND, $emailSendEvent);
 }
 public function sendAttributeSupportMail()
 {
     $user = $this->userService->getUser();
     $body = $this->templateEngine->render('OpenConextProfileBundle:AttributeSupport:email.html.twig', ['attributes' => $user->getAttributes()]);
     /** @var Message $message */
     $message = $this->mailer->createMessage();
     $message->setFrom($this->mailFrom->getEmailAddress())->setTo($this->mailTo->getEmailAddress())->setSubject(sprintf('Personal debug info of %s', $user->getId()))->setBody($body, 'text/html', 'utf-8');
     $this->mailer->send($message);
 }
Exemple #28
0
 /**
  * @param Connection $connection
  */
 public function sendConnectionCreatedEmail(Connection $connection)
 {
     $emailData = [['recipient' => $connection->getFluentSpeaker(), 'partner' => $connection->getLearner()], ['recipient' => $connection->getLearner(), 'partner' => $connection->getFluentSpeaker()]];
     foreach ($emailData as $data) {
         $parameters = ['connection' => $connection, 'recipient' => $data['recipient'], 'partner' => $data['partner']];
         $message = \Swift_Message::newInstance()->setSubject('Fikakompis/ Musikkompis från Kompisbyrån')->setFrom('*****@*****.**')->setReplyTo('*****@*****.**')->setTo($data['recipient']->getEmail(), $data['recipient']->getName())->setBody($this->templating->render('email/connectionCreated.html.twig', $parameters), 'text/html')->addPart($this->templating->render('email/connectionCreated.txt.twig', $parameters), 'text/plain');
         $this->mailer->send($message);
     }
 }
Exemple #29
0
 /**
  * Sends mail.
  * 
  * @param type $to
  */
 public function send($to)
 {
     $message = Swift_Message::newInstance($this->subject)->setFrom(array(MAIL_USERNAME => 'View Tuber'))->setTo($to)->setBody($this->body);
     if ($this->mailer->send($message)) {
         echo 'Sent';
     } else {
         echo 'Failed';
     }
 }
Exemple #30
-6
 /**
  * @param $fromEmail
  * @param BatchEntryMail $batchMail
  * @param $doSend
  */
 private function sendBatchMail($fromEmail, BatchEntryMail $batchMail, $doSend)
 {
     $receivers = $batchMail->getReceiverEntries($this->em);
     $this->writeOutput('Sending "' . $batchMail->getName() . '" mail to ' . count($receivers) . ' people from ' . $fromEmail);
     $spool = $this->mailer->getTransport()->getSpool();
     foreach ($receivers as $receiver) {
         try {
             $this->writeOutput(' -> ' . $receiver->getEmail());
             $htmlTemplate = $batchMail->getHtmlTemplate($receiver);
             $plainTextTemplate = $batchMail->getPlainTextTemplate($receiver);
             $templateData = $batchMail->getTemplateData($receiver, $this->em);
             $this->translator->setLocale($receiver->getPool()->getLocale());
             $plainTextBody = $this->twig->render($plainTextTemplate, $templateData);
             $htmlBody = $this->twig->render($htmlTemplate, $templateData);
             $message = \Swift_Message::newInstance()->setSubject($batchMail->getSubject($receiver, $this->translator))->setFrom($fromEmail, $batchMail->getFrom($receiver, $this->translator))->setTo($receiver->getEmail())->setBody($plainTextBody)->addPart($htmlBody, 'text/html');
             if ($doSend) {
                 $this->mailer->send($message);
                 $batchMail->handleMailSent($receiver, $this->em);
             }
         } catch (\Exception $e) {
             $this->writeOutput(sprintf('<error>An error occurred while sending mail for email "%s"</error>', $receiver->getEmail()));
             // mark as handled, as otherwise the system will keep retrying over and over again
             $batchMail->handleMailSent($receiver, $this->em);
         }
     }
     if ($doSend) {
         // only flush queue at the end of a batch
         $spool->flushQueue($this->transport);
     }
 }