/**
  * Sends the message
  *
  * @return void
  * @throws FailedRecipientsException Is thrown if the
  * underlying messaging service returns one or more failed
  * recipients.
  */
 public function send()
 {
     $acceptedRecipients = $this->message->send();
     $noAcceptedRecipients = 0 === $acceptedRecipients;
     $hasFailedRecipients = count($this->message->getFailedRecipients()) > 0;
     if ($noAcceptedRecipients || $hasFailedRecipients) {
         $exc = new FailedRecipientsException();
         $exc->setSenderList((array) $this->message->getSender());
         $exc->setReceiverList($this->message->getTo());
         $exc->setFailedRecipients($this->message->getFailedRecipients());
         throw $exc;
     }
 }
 /**
  * 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();
 }
 /**
  * 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();
     }
 }
Exemple #4
0
 /**
  * @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);
 }
Exemple #5
0
 /**
  * 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()]);
 }
 /**
  * @test
  * @param string|array $addresses
  * @param string|array $expected
  * @dataProvider emailAddressesDataProvider
  */
 public function setToIdnaEncodesAddresses($addresses, $expected)
 {
     $this->subject->setTo($addresses);
     $this->assertSame($expected, $this->subject->getTo());
 }