/** * @param Account $account * @return void */ protected function sendNotificationMail(Account $account) { $notificationMailSettings = $this->settings['notificationMail']; if (!$notificationMailSettings['to']) { return; } $httpRequest = Request::createFromEnvironment(); $failedAttemptsThreshold = $this->settings['failedAttemptsThreshold']; $time = (new \DateTime())->format('Y-m-d H:i'); $replacePlaceholders = function ($string) use($account, $httpRequest, $failedAttemptsThreshold, $time) { return str_replace(['{domain}', '{ip}', '{userAgent}', '{accountIdentifier}', '{failedAttemptsThreshold}', '{time}'], [$httpRequest->getUri()->getHost(), $httpRequest->getClientIpAddress(), $_SERVER['HTTP_USER_AGENT'], $account->getAccountIdentifier(), $failedAttemptsThreshold, $time], $string); }; $mail = new Message(); $mail->setFrom($replacePlaceholders($notificationMailSettings['from']['email']), $replacePlaceholders($notificationMailSettings['from']['name']))->setTo($notificationMailSettings['to'])->setSubject($replacePlaceholders($notificationMailSettings['subject']))->setBody($replacePlaceholders($notificationMailSettings['message']))->send(); }
/** * Send a new notification that a comment has been created * * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $commentNode The comment node * @param \TYPO3\TYPO3CR\Domain\Model\NodeInterface $postNode The post node * @return void */ public function sendNewCommentNotification(NodeInterface $commentNode, NodeInterface $postNode) { if ($this->settings['notifications']['to']['email'] === '') { return; } if (!class_exists('TYPO3\\SwiftMailer\\Message')) { $this->systemLogger->logException(new \TYPO3\Flow\Exception('The package "TYPO3.SwiftMailer" is required to send notifications!', 1359473932)); return; } try { $mail = new Message(); $mail->setFrom(array($commentNode->getProperty('emailAddress') => $commentNode->getProperty('author')))->setTo(array($this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']))->setSubject('New comment on blog post "' . $postNode->getProperty('title') . '"' . ($commentNode->getProperty('spam') ? ' (SPAM)' : ''))->setBody($commentNode->getProperty('text'))->send(); } catch (\Exception $e) { $this->systemLogger->logException($e); } }
/** * Sends a mail and creates a system logger entry if sending failed * * @param Message $mail * @return boolean TRUE on success, otherwise FALSE */ protected function sendMail(Message $mail) { $numberOfRecipients = 0; // ignore exceptions but log them $exceptionMessage = ''; try { $numberOfRecipients = $mail->send(); } catch (\Exception $e) { $this->systemLogger->logException($e); $exceptionMessage = $e->getMessage(); } if ($numberOfRecipients < 1) { $this->systemLogger->log('Could not send notification email "' . $mail->getSubject() . '"', LOG_ERR, ['exception' => $exceptionMessage, 'message' => $mail->getSubject(), 'id' => (string) $mail->getHeaders()->get('Message-ID')]); return false; } return true; }
/** * @param $templateIdentifier * @param \GIB\GradingTool\Domain\Model\Project $project * @param \GIB\GradingTool\Domain\Model\ProjectManager $projectManager * @param string $recipientName * @param string $recipientEmail * @param string $additionalContent * @param array $attachements * @return bool|void */ public function sendNotificationMail($templateIdentifier, \GIB\GradingTool\Domain\Model\Project $project, \GIB\GradingTool\Domain\Model\ProjectManager $projectManager = NULL, $recipientName = '', $recipientEmail = '', $additionalContent = '', $attachements = array()) { if ($this->settings['email']['activateNotifications'] === FALSE) { return TRUE; } /** @var \GIB\GradingTool\Domain\Model\Template $template */ $template = $this->templateRepository->findOneByTemplateIdentifier($templateIdentifier); $templateContentArray = unserialize($template->getContent()); // some kind of wrapper of all e-mail templates containing the HTML structure and styles $beforeContent = Files::getFileContents($this->settings['email']['beforeContentTemplate']); $afterContent = Files::getFileContents($this->settings['email']['afterContentTemplate']); /** @var \TYPO3\Fluid\View\StandaloneView $emailView */ $emailView = new \TYPO3\Fluid\View\StandaloneView(); $emailView->setTemplateSource('<f:format.raw>' . $beforeContent . $templateContentArray['content'] . $afterContent . '</f:format.raw>'); $emailView->setPartialRootPath(FLOW_PATH_PACKAGES . 'Application/GIB.GradingTool/Resources/Private/Partials'); $emailView->setFormat('html'); $emailView->assignMultiple(array('beforeContent' => $beforeContent, 'afterContent' => $afterContent, 'project' => $project, 'projectManager' => $projectManager, 'dataSheetContent' => $project->getDataSheetContentArray(), 'additionalContent' => $additionalContent)); $emailBody = $emailView->render(); /** @var \TYPO3\SwiftMailer\Message $email */ $email = new Message(); $email->setFrom(array($templateContentArray['senderEmail'] => $templateContentArray['senderName'])); // the recipient e-mail can be overridden by method arguments if (!empty($recipientEmail)) { $email->setTo(array((string) $recipientEmail => (string) $recipientName)); // in this case, send a bcc to the GIB team $email->setBcc(array($templateContentArray['senderEmail'] => $templateContentArray['senderName'])); } else { $email->setTo(array($templateContentArray['recipientEmail'] => $templateContentArray['recipientName'])); } if (!empty($attachements)) { foreach ($attachements as $attachement) { $email->attach(\Swift_Attachment::fromPath($attachement['source'])->setFilename($attachement['fileName'])); } } $email->setSubject($templateContentArray['subject']); $email->setBody($emailBody, 'text/html'); $email->send(); }
/** * Sends an activation mail for $token to the given $recipientAddress. * * The mail is built and sent according to the configuration given in the preset assigned to the $token. * * @param string $recipientAddress * @param Token $token * @param array $additionalTemplateVariables * @return int */ public function sendActivationMail($recipientAddress, Token $token, array $additionalTemplateVariables = []) { $preset = $token->getPreset(); $activationLink = $this->getActivationLink($token); $mail = new Message(); $mail->setFrom([$preset['mail']['from']['address'] => $preset['mail']['from']['name']])->setTo($recipientAddress)->setSubject($preset['mail']['subject']); $templateVariables = array_merge(['activationLink' => $activationLink, 'recipientAddress' => $recipientAddress, 'token' => $token, 'meta' => $token->getMeta()], $additionalTemplateVariables); $this->fluidView->setTemplatePathAndFilename($preset['mail']['message']['plaintext']); $this->fluidView->assignMultiple($templateVariables); $mail->setBody($this->fluidView->render(), 'text/plain'); if (isset($preset['mail']['html'])) { $this->fluidView->setTemplatePathAndFilename($preset['mail']['message']['html']); $this->fluidView->assignMultiple($templateVariables); $mail->setBody($this->fluidView->render(), 'text/html'); } return $mail->send(); }
/** * @param string $key * @param Deployment $deployment * @param SurfCaptainDeployment $surfCaptainDeployment * @return void */ protected function sendMail($key, Deployment $deployment, SurfCaptainDeployment $surfCaptainDeployment) { $settings = $this->getSettingsForFunction($key, $surfCaptainDeployment); $pathParts = pathinfo($settings['templatePathAndFilename']); $view = new StandaloneView(); $view->setTemplatePathAndFilename($settings['templatePathAndFilename']); $view->setPartialRootPath($pathParts['dirname'] . '/Partials/'); $view->setPartialRootPath($pathParts['dirname'] . '/Layouts/'); $view->assign('deployment', $deployment)->assign('surfCaptainDeployment', $surfCaptainDeployment)->assign('settings', $settings); $enabled = trim($view->renderSection('Enabled')); if (empty($enabled)) { return; } switch (strtolower($pathParts['extension'])) { case 'txt': $format = 'text/plain'; break; default: $format = 'text/html'; } $mail = new Message(); $mail->setFrom($settings['from'])->setTo($settings['to'])->setSubject(trim($view->renderSection('Subject')))->setBody(trim($view->renderSection('Body')), $format, 'utf-8'); if (!empty($settings['cc'])) { $mail->setCc($settings['cc']); } if (!empty($settings['bcc'])) { $mail->setBcc($settings['bcc']); } $mail->send(); }
/** * Sends an email to a user with the new password * * @param \TYPO3\Flow\Security\Account $account * @param array $settings * @param string $newEnteredPassword * @return boolean $success */ public function sendMail(Account $account, $settings, $newEnteredPassword = NULL) { if ($newEnteredPassword !== NULL) { $newPassword = $newEnteredPassword; } else { $newPassword = $this->algorithms->generateRandomString(10); $account->setCredentialsSource($this->hashService->hashPassword($newPassword, 'default')); $this->accountRepository->update($account); } // @TODO: Localize the email format $mailBody[] = 'Dear %1$s'; $mailBody[] = ''; $mailBody[] = 'Your password for First Visit.'; $mailBody[] = 'The password is %2$s'; $mailBody[] = ''; $mailBody[] = 'If you haven\'t requested this information, please change your password at once'; $mailBody[] = 'as others might be able to access your account'; $success = FALSE; $message = new SwiftMessage(); if ($message->setTo(array($account->getAccountIdentifier() => $account->getParty()->getName()))->setFrom(array($settings['PasswordRecovery']['Sender']['Email'] => $settings['PasswordRecovery']['Sender']['Name']))->setSubject($settings['PasswordRecovery']['Subject'])->setBody(vsprintf(implode(PHP_EOL, $mailBody), array($account->getParty()->getName(), $newPassword)))->send()) { $success = TRUE; } return $success; }
public function sendPasswordResetLink($email, $cryptJson) { $baseUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/'; $requestLink = $baseUrl . 'changepassword?code=' . $cryptJson; $templatepath = 'resource://Incvisio.LostFound/Private/Templates/Emails/ForgotPassword.html'; $this->standaloneView->setFormat('html'); $this->standaloneView->setTemplatePathAndFilename($templatepath); $this->standaloneView->assign('requestLink', $requestLink); $emailBody = $this->standaloneView->render(); $mail = new \TYPO3\SwiftMailer\Message(); $mail->setTo($email)->setFrom(array('*****@*****.**' => 'LostFound UA'))->setSubject('Reset link')->setBody($emailBody, 'text/html')->send(); }