For example 'mimepart' would create a 'message.mimepart' instance
public createMessage ( string $service = 'message' ) : object | ||
$service | string | |
Résultat | object |
/** * @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; }
/** * 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'))); }
/** * @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); }
/** * 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; }
/** * {@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); } }
/** * @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 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); }
/** * @param $subject * @param $template * @param $data * @param Request $request * @return mixed * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Exception * @throws \Twig_Error * * @return \Swift_Message */ public function createMessage($subject, $template, $data, Request $request = null) { $history = null; if ($request && $request->cookies->has('tracker_id')) { /** @var \keltanas\Bundle\TrackingBundle\Entity\History $history */ $history = $this->em->find('keltanasTrackingBundle:History', $request->cookies->get('tracker_id')); } $message = $this->mailer->createMessage()->setSubject($subject)->setFrom($this->from)->setTo($this->to)->setBody($this->templating->render($template, ['data' => $data, 'history' => $history]), 'text/html', 'utf-8'); return $message; }
/** * @param \Sonata\NotificationBundle\Model\MessageInterface $message */ private function sendEmail(MessageInterface $message) { $mail = $this->mailer->createMessage()->setSubject($message->getValue('subject'))->setFrom(array($message->getValue(array('from', 'email')) => $message->getValue(array('from', 'name'))))->setTo($message->getValue('to')); if ($text = $message->getValue(array('message', 'text'))) { $mail->addPart($text, 'text/plain'); } if ($html = $message->getValue(array('message', 'html'))) { $mail->addPart($html, 'text/html'); } $this->mailer->send($mail); }
/** * Sends reset email * @param string $email * @param string $activationHash * @return void */ public function sendResetEmail($email, $activationHash) { /** @var \Swift_Message $confirmation */ $confirmation = $this->mailer->createMessage(); $confirmation->setSubject('Reset your password'); $confirmation->setFrom($this->senderEmail); $confirmation->setTo($email); $confirmation->setReplyTo($this->senderEmail); $confirmation->setBody($this->twig->render($this->txtTwigTemplate, array('activation_hash' => $activationHash)), 'text/plain'); $confirmation->addPart($this->twig->render($this->htmlTwigTemplate, array('activation_hash' => $activationHash)), 'text/html'); $this->mailer->send($confirmation); }
/** * Sends a mail. * * @ParamType("message", type="Abc\Bundle\JobBundle\Job\Mailer\Message") * @ParamType("logger", type="@abc.logger") * * @param Message $message * @param LoggerInterface $logger * @throws \Exception Rethrows exceptions thrown by mailer */ public function send(Message $message, LoggerInterface $logger) { $logger->debug('Send mail {message}', array('message' => $message)); $mail = $this->mailer->createMessage()->setSubject($message->getSubject())->setFrom($message->getFrom())->setTo($message->getTo()); $mail->addPart($message->getMessage(), 'text/plain'); try { $this->mailer->send($mail); $this->mailer->getTransport()->stop(); } catch (\Exception $e) { $this->mailer->getTransport()->stop(); throw $e; } }
/** * @param Notification $notification * * @return \Swift_Message */ private function message(Notification $notification) { /** @var \Swift_Message $message */ $message = $this->mailer->createMessage(); $message->setSubject(ucfirst($notification->getHeaderText())); $senderName = $this->configManager->get('oro_notification.email_notification_sender_name'); $message->setFrom($this->senderEmail, $senderName); $mail = $notification->getAuthor()->getEmail(); $message->setTo($mail); $options = array('user' => $this->getFormattedUserName($notification), 'header' => $notification->getHeaderText()); $txtTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_TXT); $htmlTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_HTML); $message->setBody($this->twig->render($txtTemplate, $options), 'text/plain'); $message->addPart($this->twig->render($htmlTemplate, $options), 'text/html'); return $message; }
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; }
/** * {@inheritdoc} */ public function notify(JobExecution $jobExecution) { if (null === ($email = $this->getEmail())) { return; } $parameters = array('jobExecution' => $jobExecution, 'log' => $this->logger->getFilename()); $txtBody = $this->twig->render('AkeneoBatchBundle:Mails:notification.txt.twig', $parameters); $htmlBody = $this->twig->render('AkeneoBatchBundle:Mails:notification.html.twig', $parameters); $message = $this->mailer->createMessage(); $message->setSubject('Job has been executed'); $message->setFrom($this->senderEmail); $message->setTo($email); $message->setBody($txtBody, 'text/plain'); $message->addPart($htmlBody, 'text/html'); $this->mailer->send($message); }
/** * @param User $user * @param $plainPassword * * @return array|bool */ public function sendPassword(User $user, $plainPassword) { /* @var \Swift_Message $message */ $message = $this->mailer->createMessage(); $locale = $this->getLocale($user); $subject = T::trans('Your password', array(), 'mail', $locale); $body = T::trans('Your new password is: %plainPassword%', array('%plainPassword%' => $plainPassword), 'mail', $locale); $message->setFrom($this->mailSender); $message->setTo($user->getEmail()); $message->setSubject($subject); $message->setBody($body); $failedRecipients = array(); if (!$this->mailer->send($message, $failedRecipients)) { return $failedRecipients; } return true; }
public function sendChangeArticleStatusEmail(FormEvent $event) { /** @var Article $article */ $article = $event->getData(); $articleReview = $article->getArticleReviews()->last(); $comment = $event->getForm()->get('comment')->getData(); $to = [$article->getInscription()->getUser()->getEmail()]; /** @var Author $author */ foreach ($article->getAuthors() as $author) { if ($author->isIsNotified()) { $to[] = $author->getEmail(); } } $message = $this->mailer->createMessage()->setSubject($this->trans->trans('News from %conference%', ['%conference%' => $article->getConference()->getName()]))->setFrom($this->from)->setTo($to)->setBody($this->templating->render('email/stateEndArticle.html.twig', array('article' => $article, 'comment' => $comment))); $this->mailer->send($message); $articleReview->setState($article->getStateEnd()); }
/** * Profile registration event. * * @param MembersProfileEvent $event * @param string $eventName * @param EventDispatcherInterface $dispatcher */ public function onProfileRegister(MembersProfileEvent $event, $eventName, EventDispatcherInterface $dispatcher) { $from = [$this->config->getNotificationEmail() => $this->config->getNotificationName()]; $email = [$event->getAccount()->getEmail() => $event->getAccount()->getDisplayname()]; $subject = $this->twig->render($this->config->getTemplate('verification', 'subject'), ['member' => $event->getAccount()]); $mailHtml = $this->getRegisterHtml($event); /** @var SwiftMimeMessage $message */ $message = $this->mailer->createMessage('message')->setSubject($subject)->setBody(strip_tags($mailHtml))->addPart($mailHtml, 'text/html'); try { $message->setFrom($from)->setReplyTo($from)->setTo($email); } catch (\Swift_RfcComplianceException $e) { // Dispatch an event $event = new MembersNotificationFailureEvent($message, $e); $dispatcher->dispatch(MembersEvents::MEMBER_NOTIFICATION_FAILURE, $event); return; } $event = new MembersNotificationEvent($message); $this->queueMessage($message, $event, $dispatcher); }
/** * * @param string $subject * @param string $text * @param string $html */ protected function createMessage($subject, $text, $html) { $message = $this->mailer->createMessage(); $message->setSubject($subject)->setFrom($this->senderMail, $this->senderFullname); if (!empty($html)) { $message->setBody($html, 'text/html')->addPart($text, 'text/plain'); } else { $message->setBody($text); } return $message; }
protected function makeMessage() { $data = $this->handleData($this->event->getData()); $params = $this->handleParams($this->fc_listener->getParams()); if (!is_array($params['email_to'])) { if (strpos($params['email_to'], ',') === false) { $params['email_to'] = array($params['email_to']); } else { $params['email_to'] = explode(',', $params['email_to']); } } $message = $this->mailer->createMessage()->setSubject($params['subject'])->setFrom($params['email_from'])->setTo($params['email_to']); foreach ($data as $key => $value) { if ($value instanceof UploadedFile) { $message->attach(\Swift_Attachment::fromPath($value->getPathname())->setFilename($value->getClientOriginalName())); unset($data[$key]); } } $message->setBody($this->makeBody($data), 'text/html'); return $message; }
/** * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { if (posix_isatty(STDOUT)) { $output->writeln('<info>щ(ºДºщ) This command is pointless when not run on a cron</info>'); } $currRfcList = $this->rfcService->getLists(); $storageFile = sprintf('%s/rfcList.json', $this->config->get('storagePath')); if (!file_exists($storageFile)) { file_put_contents($storageFile, json_encode($currRfcList)); return; } $prevRfcList = json_decode(file_get_contents($storageFile), true); $diffs = $this->diffService->listDiff($currRfcList, $prevRfcList); if (empty($diffs)) { file_put_contents($storageFile, json_encode($currRfcList)); return; } $email = $this->twig->render('list.twig', ['changes' => $diffs]); $message = $this->mailer->createMessage()->setSubject('Some RFCs have moved!')->setFrom('*****@*****.**')->setTo($input->getArgument('email'))->setBody($email, 'text/html'); $this->mailer->send($message); file_put_contents($storageFile, json_encode($currRfcList)); }
function it_notifies(\Swift_Mailer $mailer, \Swift_Mime_Message $message, NotificationInterface $notification, UserInterface $user) { $notification->getUser()->shouldBeCalled()->willReturn($user); $user->getEmail()->shouldBeCalled()->willReturn('*****@*****.**'); $notification->getTitle()->shouldBeCalled()->willReturn('New issue!'); $notification->getDescription()->shouldBeCalled()->willReturn('Notification body'); $mailer->createMessage()->shouldBeCalled()->willReturn($message); $message->setTo('*****@*****.**')->shouldBeCalled()->willReturn($message); $message->setFrom('*****@*****.**')->shouldBeCalled()->willReturn($message); $message->setSubject('New issue!')->shouldBeCalled()->willReturn($message); $message->setBody('Notification body')->shouldBeCalled()->willReturn($message); $mailer->send($message)->shouldBeCalled(); $this->notify($notification); }
/** * Process email model sending. * * @param EmailModel $model * * @return EmailUser * @throws \Swift_SwiftException */ public function process(EmailModel $model) { $this->assertModel($model); $messageDate = new \DateTime('now', new \DateTimeZone('UTC')); $parentMessageId = $this->getParentMessageId($model); /** @var \Swift_Message $message */ $message = $this->mailer->createMessage(); if ($parentMessageId) { $message->getHeaders()->addTextHeader('References', $parentMessageId); $message->getHeaders()->addTextHeader('In-Reply-To', $parentMessageId); } $message->setDate($messageDate->getTimestamp()); $message->setFrom($this->getAddresses($model->getFrom())); $message->setTo($this->getAddresses($model->getTo())); $message->setCc($this->getAddresses($model->getCc())); $message->setBcc($this->getAddresses($model->getBcc())); $message->setSubject($model->getSubject()); $message->setBody($model->getBody(), $model->getType() === 'html' ? 'text/html' : 'text/plain'); $this->addAttachments($message, $model); $this->processEmbeddedImages($message, $model); $messageId = '<' . $message->generateId() . '>'; if (!$this->mailer->send($message)) { throw new \Swift_SwiftException('An email was not delivered.'); } $origin = $this->getEmailOrigin($model->getFrom()); $emailUser = $this->emailEntityBuilder->emailUser($model->getSubject(), $model->getFrom(), $model->getTo(), $messageDate, $messageDate, $messageDate, Email::NORMAL_IMPORTANCE, $model->getCc(), $model->getBcc(), $origin->getOwner(), $origin->getOrganization()); $emailUser->setFolder($origin->getFolder(FolderType::SENT)); $emailUser->getEmail()->setEmailBody($this->emailEntityBuilder->body($message->getBody(), $model->getType() === 'html', true)); $emailUser->getEmail()->setMessageId($messageId); $emailUser->setSeen(true); if ($parentMessageId) { $emailUser->getEmail()->setRefs($parentMessageId); } // persist the email and all related entities such as folders, email addresses etc. $this->emailEntityBuilder->getBatch()->persist($this->getEntityManager()); $this->persistAttachments($model, $emailUser->getEmail()); // associate the email with the target entity if exist $contexts = $model->getContexts(); foreach ($contexts as $context) { $this->emailActivityManager->addAssociation($emailUser->getEmail(), $context); } // flush all changes to the database $this->getEntityManager()->flush(); $event = new EmailBodyAdded($emailUser->getEmail()); $this->eventDispatcher->dispatch(EmailBodyAdded::NAME, $event); return $emailUser; }
/** * @param Notification $notification * @param Ticket $ticket * @param bool $isOroUser * @param string $recipientEmail * @param $changeList * * @return \Swift_Message */ private function message(Notification $notification, Ticket $ticket, $isOroUser, $recipientEmail, $changeList) { $senderEmail = $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH); $userFormattedName = $this->getFormattedUserName($notification, $ticket); /** @var \Swift_Message $message */ $message = $this->mailer->createMessage(); $message->setSubject($this->decorateMessageSubject($notification->getSubject(), $ticket)); $message->setFrom($senderEmail, $userFormattedName); $message->setTo($recipientEmail); $message->setReplyTo($senderEmail); $headers = $message->getHeaders(); $headers->addTextHeader('In-Reply-To', $this->inReplyToHeader($notification)); $headers->addIdHeader('References', $this->referencesHeader($ticket)); $options = array('changes' => $changeList, 'attachments' => $notification->getAttachments(), 'user' => $userFormattedName, 'header' => $notification->getHeaderText(), 'delimiter' => MessageReferenceServiceImpl::DELIMITER_LINE, 'isOroUser' => $isOroUser, 'ticketKey' => $ticket->getKey()); $txtTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_TXT); $htmlTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_HTML); $message->setBody($this->twig->render($txtTemplate, $options), 'text/plain'); $message->addPart($this->twig->render($htmlTemplate, $options), 'text/html'); return $message; }
/** * Process form * * @param Email $model * @return bool True on successful processing, false otherwise */ public function process(Email $model) { $result = false; if ($this->request->getMethod() === 'GET') { $this->initModel($model); } $this->form->setData($model); if (in_array($this->request->getMethod(), array('POST', 'PUT'))) { $this->form->submit($this->request); if ($this->form->isValid()) { try { $messageDate = new \DateTime('now', new \DateTimeZone('UTC')); $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(), 'text/plain'); $sent = $this->mailer->send($message); if (!$sent) { throw new \Swift_SwiftException('An email was not delivered.'); } $origin = $this->em->getRepository('OroEmailBundle:InternalEmailOrigin')->findOneBy(array('name' => InternalEmailOrigin::BAP)); $this->emailEntityBuilder->setOrigin($origin); $email = $this->emailEntityBuilder->email($model->getSubject(), $model->getFrom(), $model->getTo(), $messageDate, $messageDate, $messageDate); $email->setFolder($origin->getFolder(EmailFolder::SENT)); $emailBody = $this->emailEntityBuilder->body($model->getBody(), false, true); $email->setEmailBody($emailBody); $this->emailEntityBuilder->getBatch()->persist($this->em); $this->em->flush(); $result = true; } catch (\Exception $ex) { $this->logger->error('Email sending failed.', array('exception' => $ex)); $this->form->addError(new FormError($this->translator->trans('oro.email.handler.unable_to_send_email'))); } } } return $result; }
/** * @param $subject * @param $body * @param $toMail * @param $toName */ public function send($subject, $body, $toMail, $toName) { $message = $this->mailer->createMessage(); $message = $message->setSubject($subject)->addFrom($this->mailSender, $this->mailSenderName)->setTo($toMail, $toName)->setBody($body, 'text/html'); $this->mailer->send($message); }
/** * {@inheritdoc} */ public function notify(NotificationInterface $notification) { $message = $this->mailer->createMessage(); $message->setTo($notification->getUser()->getEmail())->setFrom('*****@*****.**')->setSubject($notification->getTitle())->setBody($notification->getDescription()); $this->mailer->send($message); }
/** * Default message * * @return \Swift_Message */ public function createDefaultMessage() { $message = $this->mailer->createMessage(); $message->setFrom("*****@*****.**"); return $message; }
/** * @param $subject * @param $to * @param $body */ public function sendEmail($subject, $to, $body) { $message = $this->mailer->createMessage()->setSubject($subject)->setFrom($this->getFrom())->setTo($to)->setBody($body, 'text/html'); $this->mailer->send($message); }
public function onPasswordReset(UserEvent $event) { $message = $this->mailer->createMessage()->setSubject('Password Reset Completed')->setFrom($this->systemEmail)->setTo($event->getUser()->getEmail())->setBody($this->twig->render('OjsUserBundle:Mails:User/password_reset_successful.html.twig', ['user' => $event->getUser()]))->setContentType('text/html'); $this->mailer->send($message); }
/** * @inheritdoc */ public function send(NotificationInterface $notification) { $message = $this->mailer->createMessage()->setFrom($this->sender)->setTo($notification->getReceiver())->setSubject($notification->getSubject())->setBody($notification->getBody(), 'text/html'); $this->mailer->send($message); }