/** * Sends the actual mail and handles autorespond message * * @return bool */ public function sendTheMail() { // Sending the mail requires the recipient and message to be set. if (!$this->mailMessage->getTo() || !trim($this->mailMessage->getBody())) { return FALSE; } $this->mailMessage->send(); // Auto response if ($this->autoRespondMessage) { $theParts = explode('/', $this->autoRespondMessage, 2); $theParts[0] = str_replace('###SUBJECT###', $this->subject, $theParts[0]); $theParts[1] = str_replace(array('/', '###MESSAGE###'), array(LF, $this->plainContent), $theParts[1]); /** @var $autoRespondMail \TYPO3\CMS\Core\Mail\MailMessage */ $autoRespondMail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); $autoRespondMail->setTo($this->fromAddress)->setSubject($theParts[0])->setFrom($this->recipient)->setBody($theParts[1]); $autoRespondMail->send(); } return $this->mailMessage->isSent(); }
/** * @param MailMessage $message * @throws \UnexpectedValueException * @throws \BadFunctionCallException */ public function log(MailMessage $message) { $tableName = ExtensionManagementUtility::isLoaded('messenger') ? 'tx_messenger_domain_model_sentmessage' : 'tx_formule_domain_model_sentmessage'; $values = ['pid' => (int) $this->getFrontendObject()->id, 'sender' => $this->formatEmails($message->getFrom()), 'recipient' => $this->formatEmails($message->getTo()), 'recipient_cc' => $this->formatEmails($message->getCc()), 'recipient_bcc' => $this->formatEmails($message->getBcc()), 'subject' => $this->getDatabaseConnection()->quoteStr($message->getSubject(), $tableName), 'body' => $this->getDatabaseConnection()->quoteStr($message->getBody(), $tableName), 'context' => (string) GeneralUtility::getApplicationContext(), 'is_sent' => (int) $message->isSent(), 'sent_time' => time(), 'ip' => GeneralUtility::getIndpEnv('REMOTE_ADDR'), 'crdate' => time()]; $this->getDatabaseConnection()->exec_INSERTquery($tableName, $values); }
/** * Sends the mail. * Sending the mail requires the recipient and message to be set. * * @return void */ protected function send() { if ($this->mailMessage->getTo() && $this->mailMessage->getBody()) { $this->mailMessage->send(); } }
/** * Log a mail message. * * @param \TYPO3\CMS\Core\Mail\MailMessage $mail Mail message * @param boolean $result Whether or not the messag was sent successfully * @return void */ public function logMessage(MailMessage $mail, $result = true) { $this->logger->log($result ? LogLevel::INFO : LogLevel::ERROR, $result ? 'Email sent' : 'Email failed to send', ['from' => $mail->getFrom(), 'to' => $mail->getTo(), 'subject' => $mail->getSubject(), 'body' => $mail->getBody()]); }