Exemplo n.º 1
0
 /**
  * Send a email using t3lib_htmlmail or the new swift mailer
  * It depends on the TYPO3 version
  */
 public static function sendEmail($to, $subject, $message, $type = 'plain', $charset = 'utf-8', $files = array())
 {
     $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $mail->setTo(explode(',', $to));
     $mail->setSubject($subject);
     $mail->setCharset($charset);
     $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
     $mail->setFrom($from);
     $mail->setReplyTo($from);
     // add Files
     if (!empty($files)) {
         foreach ($files as $file) {
             $mail->attach(Swift_Attachment::fromPath($file));
         }
     }
     // add Plain
     if ($type == 'plain') {
         $mail->addPart($message, 'text/plain');
     }
     // add HTML
     if ($type == 'html') {
         $mail->setBody($message, 'text/html');
     }
     // send
     $mail->send();
 }
Exemplo n.º 2
0
 /**
  * @param array $from  array('email' => '', 'name' => '')
  * @param array $to array('email' => '', 'name' => '')
  * @param $subject
  * @param $body
  * @return boolean
  */
 public static function sendNotification(array $from, array $to, $subject, $body)
 {
     if (!count($from)) {
         $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
     }
     $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     return $mail->setFrom(array($from['email'] => $from['name']))->setTo(array($to['email'] => $to['name']))->setSubject($subject)->setBody($body)->send();
 }
 /**
  * Sends a notification email, reporting system issues.
  *
  * @param array $systemStatus Array of statuses
  */
 protected function sendNotificationEmail(array $systemStatus)
 {
     $systemIssues = array();
     foreach ($systemStatus as $statusProvider) {
         foreach ($statusProvider as $status) {
             if ($status->getSeverity() > \TYPO3\CMS\Reports\Report\Status\Status::OK) {
                 $systemIssues[] = (string) $status;
             }
         }
     }
     $subject = sprintf($GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
     $message = sprintf($GLOBALS['LANG']->getLL('status_problemNotification'), '', '');
     $message .= CRLF . CRLF;
     $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site') . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
     $message .= CRLF . CRLF;
     $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues') . ': ' . CRLF;
     $message .= implode(CRLF, $systemIssues);
     $message .= CRLF . CRLF;
     $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
     $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $mail->setFrom($from);
     $mail->setTo($this->notificationEmail);
     $mail->setSubject($subject);
     $mail->setBody($message);
     $mail->send();
 }
Exemplo n.º 4
0
    /**
     * Send an email notification to users in workspace
     *
     * @param array $stat Workspace access array from \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::checkWorkspace()
     * @param int $stageId New Stage number: 0 = editing, 1= just ready for review, 10 = ready for publication, -1 = rejected!
     * @param string $table Table name of element (or list of element names if $id is zero)
     * @param int $id Record uid of element (if zero, then $table is used as reference to element(s) alone)
     * @param string $comment User comment sent along with action
     * @param DataHandler $tcemainObj TCEmain object
     * @param array $notificationAlternativeRecipients List of recipients to notify instead of be_users selected by sys_workspace, list is generated by workspace extension module
     * @return void
     */
    protected function notifyStageChange(array $stat, $stageId, $table, $id, $comment, DataHandler $tcemainObj, array $notificationAlternativeRecipients = array())
    {
        $workspaceRec = BackendUtility::getRecord('sys_workspace', $stat['uid']);
        // So, if $id is not set, then $table is taken to be the complete element name!
        $elementName = $id ? $table . ':' . $id : $table;
        if (!is_array($workspaceRec)) {
            return;
        }
        // Get the new stage title from workspaces library, if workspaces extension is installed
        if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
            $stageService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\StagesService::class);
            $newStage = $stageService->getStageTitle((int) $stageId);
        } else {
            // @todo CONSTANTS SHOULD BE USED - tx_service_workspace_workspaces
            // @todo use localized labels
            // Compile label:
            switch ((int) $stageId) {
                case 1:
                    $newStage = 'Ready for review';
                    break;
                case 10:
                    $newStage = 'Ready for publishing';
                    break;
                case -1:
                    $newStage = 'Element was rejected!';
                    break;
                case 0:
                    $newStage = 'Rejected element was noticed and edited';
                    break;
                default:
                    $newStage = 'Unknown state change!?';
            }
        }
        if (count($notificationAlternativeRecipients) == 0) {
            // Compile list of recipients:
            $emails = array();
            switch ((int) $stat['stagechg_notification']) {
                case 1:
                    switch ((int) $stageId) {
                        case 1:
                            $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']);
                            break;
                        case 10:
                            $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
                            break;
                        case -1:
                            // List of elements to reject:
                            $allElements = explode(',', $elementName);
                            // Traverse them, and find the history of each
                            foreach ($allElements as $elRef) {
                                list($eTable, $eUid) = explode(':', $elRef);
                                $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('log_data,tstamp,userid', 'sys_log', 'action=6 and details_nr=30
												AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($eTable, 'sys_log') . '
												AND recuid=' . (int) $eUid, '', 'uid DESC');
                                // Find all implicated since the last stage-raise from editing to review:
                                foreach ($rows as $dat) {
                                    $data = unserialize($dat['log_data']);
                                    $emails = $this->getEmailsForStageChangeNotification($dat['userid'], TRUE) + $emails;
                                    if ($data['stage'] == 1) {
                                        break;
                                    }
                                }
                            }
                            break;
                        case 0:
                            $emails = $this->getEmailsForStageChangeNotification($workspaceRec['members']);
                            break;
                        default:
                            $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
                    }
                    break;
                case 10:
                    $emails = $this->getEmailsForStageChangeNotification($workspaceRec['adminusers'], TRUE);
                    $emails = $this->getEmailsForStageChangeNotification($workspaceRec['reviewers']) + $emails;
                    $emails = $this->getEmailsForStageChangeNotification($workspaceRec['members']) + $emails;
                    break;
                default:
                    // Do nothing
            }
        } else {
            $emails = $notificationAlternativeRecipients;
        }
        // prepare and then send the emails
        if (count($emails)) {
            // Path to record is found:
            list($elementTable, $elementUid) = explode(':', $elementName);
            $elementUid = (int) $elementUid;
            $elementRecord = BackendUtility::getRecord($elementTable, $elementUid);
            $recordTitle = BackendUtility::getRecordTitle($elementTable, $elementRecord);
            if ($elementTable == 'pages') {
                $pageUid = $elementUid;
            } else {
                BackendUtility::fixVersioningPid($elementTable, $elementRecord);
                $pageUid = $elementUid = $elementRecord['pid'];
            }
            // fetch the TSconfig settings for the email
            // old way, options are TCEMAIN.notificationEmail_body/subject
            $TCEmainTSConfig = $tcemainObj->getTCEMAIN_TSconfig($pageUid);
            // new way, options are
            // pageTSconfig: tx_version.workspaces.stageNotificationEmail.subject
            // userTSconfig: page.tx_version.workspaces.stageNotificationEmail.subject
            $pageTsConfig = BackendUtility::getPagesTSconfig($pageUid);
            $emailConfig = $pageTsConfig['tx_version.']['workspaces.']['stageNotificationEmail.'];
            $markers = array('###RECORD_TITLE###' => $recordTitle, '###RECORD_PATH###' => BackendUtility::getRecordPath($elementUid, '', 20), '###SITE_NAME###' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], '###SITE_URL###' => GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, '###WORKSPACE_TITLE###' => $workspaceRec['title'], '###WORKSPACE_UID###' => $workspaceRec['uid'], '###ELEMENT_NAME###' => $elementName, '###NEXT_STAGE###' => $newStage, '###COMMENT###' => $comment, '###USER_REALNAME###' => $tcemainObj->BE_USER->user['realName'], '###USER_FULLNAME###' => $tcemainObj->BE_USER->user['realName'], '###USER_USERNAME###' => $tcemainObj->BE_USER->user['username']);
            // add marker for preview links if workspace extension is loaded
            if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
                $this->workspaceService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
                // only generate the link if the marker is in the template - prevents database from getting to much entries
                if (GeneralUtility::isFirstPartOfStr($emailConfig['message'], 'LLL:')) {
                    $tempEmailMessage = $GLOBALS['LANG']->sL($emailConfig['message']);
                } else {
                    $tempEmailMessage = $emailConfig['message'];
                }
                if (strpos($tempEmailMessage, '###PREVIEW_LINK###') !== FALSE) {
                    $markers['###PREVIEW_LINK###'] = $this->workspaceService->generateWorkspacePreviewLink($elementUid);
                }
                unset($tempEmailMessage);
                $markers['###SPLITTED_PREVIEW_LINK###'] = $this->workspaceService->generateWorkspaceSplittedPreviewLink($elementUid, TRUE);
            }
            // Hook for preprocessing of the content for formmails:
            if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/version/class.tx_version_tcemain.php']['notifyStageChange-postModifyMarkers'])) {
                foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/version/class.tx_version_tcemain.php']['notifyStageChange-postModifyMarkers'] as $_classRef) {
                    $_procObj =& GeneralUtility::getUserObj($_classRef);
                    $markers = $_procObj->postModifyMarkers($markers, $this);
                }
            }
            // send an email to each individual user, to ensure the
            // multilanguage version of the email
            $emailRecipients = array();
            // an array of language objects that are needed
            // for emails with different languages
            $languageObjects = array($GLOBALS['LANG']->lang => $GLOBALS['LANG']);
            // loop through each recipient and send the email
            foreach ($emails as $recipientData) {
                // don't send an email twice
                if (isset($emailRecipients[$recipientData['email']])) {
                    continue;
                }
                $emailSubject = $emailConfig['subject'];
                $emailMessage = $emailConfig['message'];
                $emailRecipients[$recipientData['email']] = $recipientData['email'];
                // check if the email needs to be localized
                // in the users' language
                if (GeneralUtility::isFirstPartOfStr($emailSubject, 'LLL:') || GeneralUtility::isFirstPartOfStr($emailMessage, 'LLL:')) {
                    $recipientLanguage = $recipientData['lang'] ? $recipientData['lang'] : 'default';
                    if (!isset($languageObjects[$recipientLanguage])) {
                        // a LANG object in this language hasn't been
                        // instantiated yet, so this is done here
                        /** @var $languageObject \TYPO3\CMS\Lang\LanguageService */
                        $languageObject = GeneralUtility::makeInstance(\TYPO3\CMS\Lang\LanguageService::class);
                        $languageObject->init($recipientLanguage);
                        $languageObjects[$recipientLanguage] = $languageObject;
                    } else {
                        $languageObject = $languageObjects[$recipientLanguage];
                    }
                    if (GeneralUtility::isFirstPartOfStr($emailSubject, 'LLL:')) {
                        $emailSubject = $languageObject->sL($emailSubject);
                    }
                    if (GeneralUtility::isFirstPartOfStr($emailMessage, 'LLL:')) {
                        $emailMessage = $languageObject->sL($emailMessage);
                    }
                }
                $emailSubject = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($emailSubject, $markers, '', TRUE, TRUE);
                $emailMessage = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($emailMessage, $markers, '', TRUE, TRUE);
                // Send an email to the recipient
                /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
                if (!empty($recipientData['realName'])) {
                    $recipient = array($recipientData['email'] => $recipientData['realName']);
                } else {
                    $recipient = $recipientData['email'];
                }
                $mail->setTo($recipient)->setSubject($emailSubject)->setFrom(\TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom())->setBody($emailMessage);
                $mail->send();
            }
            $emailRecipients = implode(',', $emailRecipients);
            $tcemainObj->newlog2('Notification email for stage change was sent to "' . $emailRecipients . '"', $table, $id);
        }
    }
Exemplo n.º 5
0
 /**
  * Sends a notification email
  *
  * @param string $message The message content. If blank, no email is sent.
  * @param string $recipients Comma list of recipient email addresses
  * @param string $cc Email address of recipient of an extra mail. The same mail will be sent ONCE more; not using a CC header but sending twice.
  * @param string $senderAddress "From" email address
  * @param string $senderName Optional "From" name
  * @param string $replyTo Optional "Reply-To" header email address.
  * @return boolean Returns TRUE if sent
  */
 public function sendNotifyEmail($message, $recipients, $cc, $senderAddress, $senderName = '', $replyTo = '')
 {
     $result = FALSE;
     /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
     $mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $senderName = trim($senderName);
     $senderAddress = trim($senderAddress);
     if ($senderName !== '' && $senderAddress !== '') {
         $sender = array($senderAddress => $senderName);
     } elseif ($senderAddress !== '') {
         $sender = array($senderAddress);
     } else {
         $sender = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
     }
     $mail->setFrom($sender);
     $parsedReplyTo = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($replyTo);
     if (count($parsedReplyTo) > 0) {
         $mail->setReplyTo($parsedReplyTo);
     }
     $message = trim($message);
     if ($message !== '') {
         // First line is subject
         $messageParts = explode(LF, $message, 2);
         $subject = trim($messageParts[0]);
         $plainMessage = trim($messageParts[1]);
         $parsedRecipients = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($recipients);
         if (count($parsedRecipients) > 0) {
             $mail->setTo($parsedRecipients)->setSubject($subject)->setBody($plainMessage);
             $mail->send();
         }
         $parsedCc = \TYPO3\CMS\Core\Utility\MailUtility::parseAddresses($cc);
         if (count($parsedCc) > 0) {
             /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
             $mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
             if (count($parsedReplyTo) > 0) {
                 $mail->setReplyTo($parsedReplyTo);
             }
             $mail->setFrom($sender)->setTo($parsedCc)->setSubject($subject)->setBody($plainMessage);
             $mail->send();
         }
         $result = TRUE;
     }
     return $result;
 }
 /**
  * Sends a notification email, reporting system issues.
  *
  * @param Status[] $systemStatus Array of statuses
  * @return void
  */
 protected function sendNotificationEmail(array $systemStatus)
 {
     $systemIssues = array();
     foreach ($systemStatus as $statusProvider) {
         /** @var Status $status */
         foreach ($statusProvider as $status) {
             if ($status->getSeverity() > Status::OK) {
                 $systemIssues[] = (string) $status . CRLF . $status->getMessage() . CRLF . CRLF;
             }
         }
     }
     $notificationEmails = GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
     $sendEmailsTo = array();
     foreach ($notificationEmails as $notificationEmail) {
         $sendEmailsTo[] = $notificationEmail;
     }
     $subject = sprintf($this->getLanguageService()->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
     $message = sprintf($this->getLanguageService()->getLL('status_problemNotification'), '', '');
     $message .= CRLF . CRLF;
     $message .= $this->getLanguageService()->getLL('status_updateTask_email_site') . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
     $message .= CRLF . CRLF;
     $message .= $this->getLanguageService()->getLL('status_updateTask_email_issues') . ': ' . CRLF;
     $message .= implode(CRLF, $systemIssues);
     $message .= CRLF . CRLF;
     $from = MailUtility::getSystemFrom();
     /** @var MailMessage $mail */
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     $mail->setFrom($from);
     $mail->setTo($sendEmailsTo);
     $mail->setSubject($subject);
     $mail->setBody($message);
     $mail->send();
 }
 /**
  * Will send an email notification to warning_email_address/the login users email address when a login session is just started.
  * Depends on various parameters whether mails are send and to whom.
  *
  * @return void
  * @access private
  */
 private function emailAtLogin()
 {
     if ($this->loginSessionStarted) {
         // Send notify-mail
         $subject = 'At "' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '"' . ' from ' . GeneralUtility::getIndpEnv('REMOTE_ADDR') . (GeneralUtility::getIndpEnv('REMOTE_HOST') ? ' (' . GeneralUtility::getIndpEnv('REMOTE_HOST') . ')' : '');
         $msg = sprintf('User "%s" logged in from %s (%s) at "%s" (%s)', $this->user['username'], GeneralUtility::getIndpEnv('REMOTE_ADDR'), GeneralUtility::getIndpEnv('REMOTE_HOST'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'], GeneralUtility::getIndpEnv('HTTP_HOST'));
         // Warning email address
         if ($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr']) {
             $warn = 0;
             $prefix = '';
             if ((int) $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_mode'] & 1) {
                 // first bit: All logins
                 $warn = 1;
                 $prefix = $this->isAdmin() ? '[AdminLoginWarning]' : '[LoginWarning]';
             }
             if ($this->isAdmin() && (int) $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_mode'] & 2) {
                 // second bit: Only admin-logins
                 $warn = 1;
                 $prefix = '[AdminLoginWarning]';
             }
             if ($warn) {
                 $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                 /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
                 $mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
                 $mail->setTo($GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'])->setFrom($from)->setSubject($prefix . ' ' . $subject)->setBody($msg);
                 $mail->send();
             }
         }
         // If An email should be sent to the current user, do that:
         if ($this->uc['emailMeAtLogin'] && strstr($this->user['email'], '@')) {
             $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
             /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
             $mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
             $mail->setTo($this->user['email'])->setFrom($from)->setSubject($subject)->setBody($msg);
             $mail->send();
         }
     }
 }
 /**
  * Create a new Message.
  *
  * Details may be optionally passed into the constructor.
  *
  * @param string $subject
  * @param string $body
  * @param string $contentType
  * @param string $charset
  */
 public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
 {
     parent::__construct($subject, $body, $contentType, $charset);
     $this->setFrom(MailUtility::getSystemFrom());
 }
Exemplo n.º 9
0
 /**
  * @param  array  $msg
  * @return string
  */
 public function mailAction(array $msg = array())
 {
     $recipient = $this->widgetConfiguration['recipient'];
     $sender = $this->widgetConfiguration['sender'];
     $required = $this->widgetConfiguration['required'];
     $missing = array();
     /* example: $required = [ 'name', 'email,phone' ] => name and (phone or email) are required.*/
     foreach ($required as $orFieldList) {
         $orFields = explode(',', $orFieldList);
         $found = false;
         foreach ($orFields as $field) {
             if (array_key_exists($field, $msg) && strlen($msg[$field]) != 0) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             foreach ($orFields as $field) {
                 $missing[] = $field;
             }
         }
     }
     if (count($missing)) {
         return json_encode(array('status' => 'fields-missing', 'missing' => $missing));
     }
     if (!is_array($recipient) || !array_key_exists('email', $recipient)) {
         /* TODO: Throw exception instead. */
         return json_encode(array('status' => 'internal-error', 'error' => '$recipient is not valid'));
     }
     if (isset($recipient['name']) && strlen($recipient['name']) > 0) {
         $tmp = $recipient;
         $recipient = array();
         foreach (GeneralUtility::trimExplode(',', $tmp['email']) as $email) {
             $recipient[$email] = $tmp['name'];
         }
     } else {
         $recipient = GeneralUtility::trimExplode(',', $recipient['email']);
     }
     $sender = $sender !== null ? array($sender['email'] => $sender['name']) : MailUtility::getSystemFrom();
     $recipientSave = $recipient;
     $recipientOverwrite = $this->widgetConfiguration['receiver_overwrite_email'];
     if ($recipientOverwrite !== null) {
         $recipient = $recipientOverwrite;
     }
     $params = array('to' => $recipient, 'from' => $sender, 'msg' => $msg);
     $view = GeneralUtility::makeInstance('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
     $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($this->widgetConfiguration['mailTemplate']));
     $view->assignMultiple($params);
     $text = $view->render();
     list($subject, $body) = explode("\n", $text, 2);
     if ($recipientOverwrite !== null) {
         $subject .= ' – Recipient: ' . implode(',', $recipientSave);
     }
     $mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $mail->setFrom($sender);
     $mail->setTo($recipient);
     $mail->setSubject($subject);
     $mail->setBody(trim($body));
     if (isset($msg['email']) && strlen($msg['email']) > 0) {
         $mail->setReplyTo($msg['email']);
     }
     $mail->send();
     return json_encode(array('status' => 'ok'));
 }
Exemplo n.º 10
0
 /**
  * action create
  *
  * @param News $newNews
  * @param string $link
  * @return void
  */
 public function createAction(News $newNews, $link = '')
 {
     $newNews->setDatetime(new \DateTime());
     if (empty($this->settings['enableNewItemsByDefault'])) {
         $newNews->setHidden(1);
     }
     if ($link !== '') {
         $linkObject = new \Tx_News_Domain_Model_Link();
         $linkObject->setUri($link);
         $linkObject->setTitle($link);
         $newNews->addRelatedLink($linkObject);
     }
     // save news
     $this->newsRepository->add($newNews);
     $this->addFlashMessage(LocalizationUtility::translate('news.created', $this->extensionName));
     // send mail
     if ($this->settings['recipientMail']) {
         /** @var $message \TYPO3\CMS\Core\Mail\MailMessage */
         $message = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
         $from = MailUtility::getSystemFrom();
         $message->setFrom($from)->setTo(array($this->settings['recipientMail'] => 'News Manager'))->setSubject('[New News] ' . $newNews->getTitle())->setBody('<h1>New News</h1>' . $newNews->getBodytext(), 'text/html')->send();
     }
     // clear page cache after save
     if (!$newNews->getHidden()) {
         $this->flushNewsCache($newNews);
     }
     // go to thank you action
     $this->redirect('thankyou');
 }
Exemplo n.º 11
0
 /**
  * @param string $templateName
  * @param array $sender
  * @return bool|array
  */
 protected function cleanSender($templateName, array $sender = NULL)
 {
     if ($sender) {
         return $sender;
     }
     if (isset($this->settings['templates'][$templateName]) && isset($this->settings['templates'][$templateName]['sender'])) {
         $senderInfo = $this->settings['templates'][$templateName]['sender'];
         return array($senderInfo['email'] => $senderInfo['name']);
     }
     if ($this->hasDefaultSender()) {
         return $this->defaultSender;
     }
     $systemDefault = MailUtility::getSystemFrom();
     if ($systemDefault) {
         return $systemDefault;
     }
     return FALSE;
 }
Exemplo n.º 12
0
 /**
  * @param Model\Project $project
  * @param array         $receivers
  * @param bool          $isAccepted
  */
 public function updateStatusMail(Model\Project $project, array $receivers = [], $isAccepted = true)
 {
     $noReply = null;
     if ($this->settings['mail']['noReplyEmail'] && CoreUtility\GeneralUtility::validEmail($this->settings['mail']['noReplyEmail'])) {
         $noReply = [$this->settings['mail']['noReplyEmail'] => $this->settings['mail']['noReplyName'] ?: $this->settings['mail']['senderName']];
     }
     $carbonCopyReceivers = [];
     if ($this->settings['mail']['carbonCopy']) {
         foreach (explode(',', $this->settings['mail']['carbonCopy']) as $carbonCopyReceiver) {
             $tokens = CoreUtility\GeneralUtility::trimExplode(' ', $carbonCopyReceiver, true, 2);
             if (CoreUtility\GeneralUtility::validEmail($tokens[0])) {
                 $carbonCopyReceivers[$tokens[0]] = $tokens[1];
             }
         }
     }
     /** @var \TYPO3\CMS\Core\Mail\MailMessage $mailToSender */
     $mailToSender = CoreUtility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
     $mailToSender->setContentType('text/html');
     /**
      * Email to sender
      */
     $mailToSender->setFrom($noReply ?: CoreUtility\MailUtility::getSystemFrom())->setTo([$project->getRegistrant()->getEmail() => $project->getRegistrant()->getName()])->setCc($receivers)->setSubject(($this->settings['mail']['projectStatusUpdateSubject'] ?: (Lang::translate('mail_project_status_update_subject', $this->extensionName) ?: 'Project status update')) . " #{$project->getUid()}")->setBody($this->getStandAloneTemplate(CoreUtility\ExtensionManagementUtility::siteRelPath(CoreUtility\GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName)) . 'Resources/Private/Templates/Email/ProjectStatusUpdated.html', ['settings' => $this->settings, 'project' => $project, 'accepted' => $isAccepted, 'addressees' => $this->getAddressees()]))->send();
 }
 /**
  * Sends a notification email
  *
  * @param  string     $recipients  comma-separated list of email addresses that should
  *                                 receive the notification
  * @param  array      $config      notification configuration
  * @param  object     $media       one or multiple media records (QueryResult)
  * @param  \Exception $exception   the exception that was thrown
  * @return boolean                 success status of email
  */
 protected function sendNotification($recipients, array $config, $media, \Exception $exception = NULL)
 {
     // Convert comma-separated list to array
     $recipients = array_map('trim', explode(',', $recipients));
     // Generate markers for the email subject and content
     $markers = array('###SIGNATURE###' => $config['signature']);
     if (isset($exception)) {
         $markers['###ERROR###'] = $exception->getMessage();
         $markers['###ERROR_FILE###'] = $exception->getFile();
         $markers['###ERROR_LINE###'] = $exception->getLine();
     }
     // Generate list of media files for the email
     $allMedia = $media instanceof Media ? array($media) : $media->toArray();
     $mediaFiles = array();
     foreach ($allMedia as $oneMedia) {
         // Get all properties of media record that can be outputted
         $mediaMarkers = array();
         foreach ($oneMedia->toArray() as $key => $value) {
             if (!is_object($value)) {
                 $mediaMarkers[$key] = $value;
             }
         }
         // Provide properties as markers
         $mediaFiles[] = $this->cObj->substituteMarkerArray($config['mediafiles'], $mediaMarkers, '###|###', TRUE);
     }
     $markers['###MEDIAFILES###'] = implode("\n", $mediaFiles);
     // Replace markers in subject and content
     $subject = $this->cObj->substituteMarkerArray($config['subject'], $markers);
     $message = $this->cObj->substituteMarkerArray($config['message'], $markers);
     // Send email
     return $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage')->setFrom(\TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom())->setTo($recipients)->setSubject($subject)->setBody($message)->send();
 }
Exemplo n.º 14
0
 /**
  * Sends a notification email
  *
  * @param string $message The message content. If blank, no email is sent.
  * @param string $recipients Comma list of recipient email addresses
  * @param string $cc Email address of recipient of an extra mail. The same mail will be sent ONCE more; not using a CC header but sending twice.
  * @param string $senderAddress "From" email address
  * @param string $senderName Optional "From" name
  * @param string $replyTo Optional "Reply-To" header email address.
  * @return bool Returns TRUE if sent
  */
 public function sendNotifyEmail($message, $recipients, $cc, $senderAddress, $senderName = '', $replyTo = '')
 {
     /** @var $mail MailMessage */
     $mail = GeneralUtility::makeInstance(MailMessage::class);
     $senderName = trim($senderName);
     $senderAddress = trim($senderAddress);
     if ($senderName !== '' && $senderAddress !== '') {
         $sender = array($senderAddress => $senderName);
     } elseif ($senderAddress !== '') {
         $sender = array($senderAddress);
     } else {
         $sender = MailUtility::getSystemFrom();
     }
     $mail->setFrom($sender);
     $parsedReplyTo = MailUtility::parseAddresses($replyTo);
     if (!empty($parsedReplyTo)) {
         $mail->setReplyTo($parsedReplyTo);
     }
     $message = trim($message);
     if ($message !== '') {
         // First line is subject
         $messageParts = explode(LF, $message, 2);
         $subject = trim($messageParts[0]);
         $plainMessage = trim($messageParts[1]);
         $parsedRecipients = MailUtility::parseAddresses($recipients);
         if (!empty($parsedRecipients)) {
             $mail->setTo($parsedRecipients)->setSubject($subject)->setBody($plainMessage);
             $mail->send();
         }
         $parsedCc = MailUtility::parseAddresses($cc);
         if (!empty($parsedCc)) {
             /** @var $mail MailMessage */
             $mail = GeneralUtility::makeInstance(MailMessage::class);
             if (!empty($parsedReplyTo)) {
                 $mail->setReplyTo($parsedReplyTo);
             }
             $mail->setFrom($sender)->setTo($parsedCc)->setSubject($subject)->setBody($plainMessage);
             $mail->send();
         }
         return true;
     }
     return false;
 }
Exemplo n.º 15
0
 /**
  * This is the main-function for sending Mails
  *
  * @param array $mailTo
  * @param array $mailFrom
  * @param string $subject
  * @param string $emailBody
  *
  * @return integer the number of recipients who were accepted for delivery
  */
 public function send($mailTo, $mailFrom, $subject, $emailBody)
 {
     if (!($mailTo && is_array($mailTo) && GeneralUtility::validEmail(key($mailTo)))) {
         $this->log->error('Given mailto email address is invalid.', $mailTo);
         return FALSE;
     }
     if (!($mailFrom && is_array($mailFrom) && GeneralUtility::validEmail(key($mailFrom)))) {
         $mailFrom = MailUtility::getSystemFrom();
     }
     /* @var $message \TYPO3\CMS\Core\Mail\MailMessage */
     $message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setTo($mailTo)->setFrom($mailFrom)->setSubject($subject)->setCharset(\TYPO3\T3extblog\Utility\GeneralUtility::getTsFe()->metaCharset);
     // send text or html emails
     if (strip_tags($emailBody) === $emailBody) {
         $message->setBody($emailBody, 'text/plain');
     } else {
         $message->setBody($emailBody, 'text/html');
     }
     if (!$this->settings['debug']['disableEmailTransmission']) {
         $message->send();
     }
     $logData = array('mailTo' => $mailTo, 'mailFrom' => $mailFrom, 'subject' => $subject, 'emailBody' => $emailBody, 'isSent' => $message->isSent());
     $this->log->dev('Email sent.', $logData);
     return $logData['isSent'];
 }
 /**
  * Logs message to the system log.
  * This should be implemented around the source code, including the Core and both frontend and backend, logging serious errors.
  * If you want to implement the sysLog in your applications, simply add lines like:
  * \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('[write message in English here]', 'extension_key', 'severity');
  *
  * @param string $msg Message (in English).
  * @param string $extKey Extension key (from which extension you are calling the log) or "Core
  * @param integer $severity \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_* constant
  * @return void
  */
 public static function sysLog($msg, $extKey, $severity = 0)
 {
     $severity = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($severity, 0, 4);
     // Is message worth logging?
     if ((int) $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] > $severity) {
         return;
     }
     // Initialize logging
     if (!$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit']) {
         self::initSysLog();
     }
     // Do custom logging
     if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'])) {
         $params = array('msg' => $msg, 'extKey' => $extKey, 'backTrace' => debug_backtrace(), 'severity' => $severity);
         $fakeThis = FALSE;
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog'] as $hookMethod) {
             self::callUserFunction($hookMethod, $params, $fakeThis);
         }
     }
     // TYPO3 logging enabled?
     if (!$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog']) {
         return;
     }
     $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
     $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
     // Use all configured logging options
     foreach (explode(';', $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'], 2) as $log) {
         list($type, $destination, $level) = explode(',', $log, 4);
         // Is message worth logging for this log type?
         if ((int) $level > $severity) {
             continue;
         }
         $msgLine = ' - ' . $extKey . ': ' . $msg;
         // Write message to a file
         if ($type == 'file') {
             $file = fopen($destination, 'a');
             if ($file) {
                 fwrite($file, date($dateFormat . ' ' . $timeFormat) . $msgLine . LF);
                 fclose($file);
                 self::fixPermissions($destination);
             }
         } elseif ($type == 'mail') {
             list($to, $from) = explode('/', $destination);
             if (!self::validEmail($from)) {
                 $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
             }
             /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
             $mail = self::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
             $mail->setTo($to)->setFrom($from)->setSubject('Warning - error in TYPO3 installation')->setBody('Host: ' . $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] . LF . 'Extension: ' . $extKey . LF . 'Severity: ' . $severity . LF . LF . $msg);
             $mail->send();
         } elseif ($type == 'error_log') {
             error_log($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogHost'] . $msgLine, 0);
         } elseif ($type == 'syslog') {
             $priority = array(LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT);
             syslog($priority[(int) $severity], $msgLine);
         }
     }
 }
 /**
  * Notifies participants for the next event
  *
  * @return void
  */
 public function notifyCommand()
 {
     $this->settings = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
     $eventStartTime = $this->settings['eventStartTime'];
     $participantGroupId = $this->settings['participantGroupId'];
     $eventPageUid = $this->settings['eventPageUid'];
     $offset = 0;
     $eventStartDate = $this->div->nextEventDate($offset);
     $events = $this->eventRepository->findByStart($eventStartDate->format("Y-m-d H:i:s"));
     if ($events->count() == 0) {
         $this->div->createEvent($eventStartDate);
         $events = $this->eventRepository->findByStart($eventStartDate->format("Y-m-d H:i:s"));
     }
     if ($events->getFirst()->getActive()) {
         $this->initFrontend();
         $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         $link = $cObj->typolink_URL(array('parameter' => "{$eventPageUid}", 'forceAbsoluteUrl' => 1));
         $acceptUrl = $link . "?&tx_pceventscheduler_pceventscheduler%5Baction%5D=accept";
         $cancelUrl = $link . "?&tx_pceventscheduler_pceventscheduler%5Baction%5D=cancel";
         $participantsUnknown = $this->participantRepository->findParticipantsUnknown($events->getFirst()->getUid(), $participantGroupId);
         if (isset($participantsUnknown)) {
             foreach ($participantsUnknown as $participantUnknown) {
                 $receiverEmail = $participantUnknown['email'];
                 $receiverName = $participantUnknown['name'];
                 $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
                 $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
                 $mail->setFrom($from);
                 $mail->setSubject($this->settings['notifyMailSubject']);
                 $mail->setTo($receiverEmail);
                 $mail->setBody(str_replace(array('###name###', '###eventdate###', '###eventtime###', '###eventlocation###', '###acceptlink###', '###cancellink###'), array($receiverName, $events->getFirst()->getStart()->format("d.m.Y"), $eventStartTime, $events->getFirst()->getLocation(), $acceptUrl, $cancelUrl), $this->settings['notifyMailBody']), 'text/html');
                 $mail->send();
             }
         }
     }
     return true;
 }