Beispiel #1
0
 public function render()
 {
     if ($this->mailMessage->isSent()) {
         $output = $this->success();
     } else {
         $output = $this->error();
     }
     return $output;
 }
 /**
  * Attaches the given array of files to the email message
  *
  * @param array $attachments
  * @return void
  */
 protected function addAttachments($attachments)
 {
     if (count($attachments) > 0) {
         foreach ($attachments as $attachment) {
             if (file_exists($attachment)) {
                 $this->mailer->attach(\Swift_Attachment::fromPath($attachment));
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Send mail or throw an exception
  *
  * @return int
  * @throws \Exception
  */
 protected function sendMail()
 {
     try {
         return $this->mail->send();
     } catch (\Exception $ex) {
         throw new \Exception('MailView: ' . $ex->getMessage());
     }
 }
 /**
  * send email on new/update.
  *
  * @param string                                    $subjectKey
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  *
  * @return int The amound of email receivers
  */
 public function sendMail($subjectKey, \JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     $this->view->assign('club', $club);
     $this->mail->setFrom($this->extConf->getEmailFromAddress(), $this->extConf->getEmailFromName());
     $this->mail->setTo($this->extConf->getEmailToAddress(), $this->extConf->getEmailToName());
     $this->mail->setSubject(LocalizationUtility::translate('email.subject.' . $subjectKey, 'clubdirectory'));
     $this->mail->setBody($this->view->render(), 'text/html');
     return $this->mail->send();
 }
 /**
  * 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;
     }
 }
Beispiel #6
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  *
  * @return bool true/false if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name)
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->mail->setFrom($sender, $name);
         $this->mail->setSubject($subject);
         $this->mail->setBody($body, 'text/html');
         $this->mail->setTo($recipient);
         $this->mail->send();
         return $this->mail->isSent();
     } else {
         return false;
     }
 }
Beispiel #7
0
 /**
  * Sends the message.
  *
  * @return integer the number of recipients who were accepted for delivery
  */
 public function send()
 {
     $redirectTo = $this->getRedirectService()->redirectionForCurrentContext();
     // Means we want to redirect email.
     if (!empty($redirectTo)) {
         $body = $this->addDebugInfoToBody($this->getBody());
         $this->setBody($body);
         $this->setTo($redirectTo);
         $this->setCc(array());
         // reset cc which was written as debug in the body message previously.
         $this->setBcc(array());
         // same remark as bcc.
         $subject = strtoupper((string) GeneralUtility::getApplicationContext()) . ' CONTEXT! ' . $this->getSubject();
         $this->setSubject($subject);
     }
     return parent::send();
 }
 /**
  * Loop through all elements of the session and attach the file
  * if its a uploaded file
  *
  * @return void
  */
 protected function addAttachmentsFromSession()
 {
     $sessionData = $this->sessionUtility->getSessionData();
     if (is_array($sessionData)) {
         foreach ($sessionData as $fieldName => $values) {
             if (is_array($values)) {
                 foreach ($values as $file) {
                     if (isset($file['tempFilename'])) {
                         if (is_file($file['tempFilename']) && GeneralUtility::isAllowedAbsPath($file['tempFilename'])) {
                             $this->mailMessage->attach(\Swift_Attachment::fromPath($file['tempFilename'])->setFilename($file['name']));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * 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();
 }
 /**
  * Loop through all elements and attach the file when the element
  * is a fileupload
  *
  * @param array $elements
  * @param array $submittedValues
  * @return void
  */
 protected function addAttachmentsFromElements($elements, $submittedValues)
 {
     /** @var $element \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement */
     foreach ($elements as $element) {
         if (is_a($element, 'TYPO3\\CMS\\Form\\Domain\\Model\\Element\\ContainerElement')) {
             $this->addAttachmentsFromElements($element->getElements(), $submittedValues);
             continue;
         }
         if (is_a($element, 'TYPO3\\CMS\\Form\\Domain\\Model\\Element\\FileuploadElement')) {
             $elementName = $element->getName();
             if (is_array($submittedValues[$elementName]) && isset($submittedValues[$elementName]['tempFilename'])) {
                 $filename = $submittedValues[$elementName]['tempFilename'];
                 if (is_file($filename) && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($filename)) {
                     $this->mailMessage->attach(\Swift_Attachment::fromPath($filename)->setFilename($submittedValues[$elementName]['originalFilename']));
                 }
             }
         }
     }
 }
 /**
  * Add mail body plain
  *
  * @param MailMessage $message
  * @param array $email
  * @return MailMessage
  */
 protected function addPlainBody(MailMessage $message, array $email)
 {
     if ($email['format'] !== 'html') {
         $message->addPart($this->makePlain($this->createEmailBody($email)), 'text/plain');
     }
     return $message;
 }
Beispiel #12
0
 /**
  * Set Sender Header according to RFC 2822 - 3.6.2 Originator fields
  *
  * @param MailMessage $message
  * @return MailMessage
  */
 protected function addSenderHeader(MailMessage $message)
 {
     $senderHeaderConfig = $this->configuration[$this->type . '.']['senderHeader.'];
     $email = $this->contentObject->cObjGetSingle($senderHeaderConfig['email'], $senderHeaderConfig['email.']);
     $name = $this->contentObject->cObjGetSingle($senderHeaderConfig['name'], $senderHeaderConfig['name.']);
     if (GeneralUtility::validEmail($email)) {
         if (empty($name)) {
             $name = null;
         }
         $message->setSender($email, $name);
     }
     return $message;
 }
Beispiel #13
0
 /**
  * @param MailMessage $message
  * @return void
  */
 protected function sendEmail(MailMessage $message)
 {
     $message->send();
 }
Beispiel #14
0
 /**
  * Initializes the message instance.
  *
  * @param \TYPO3\CMS\Core\Mail\MailMessage $object TYPO3 mail object
  * @param string $charset Default charset of the message
  */
 public function __construct(\TYPO3\CMS\Core\Mail\MailMessage $object, $charset)
 {
     $object->setCharset($charset);
     $this->object = $object;
 }
 public function embed($image)
 {
     return $this->emailObj->embed(\Swift_Image::fromPath($image));
 }
Beispiel #16
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()]);
 }
 /**
  * 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());
 }
Beispiel #18
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);
 }
 /**
  * @test
  * @param string|array $addresses
  * @param string|array $expected
  * @dataProvider emailAddressesDataProvider
  */
 public function setReadReceiptToIdnaEncodesAddresses($addresses, $expected)
 {
     $this->subject->setReadReceiptTo($addresses);
     $this->assertSame($expected, $this->subject->getReadReceiptTo());
 }