Example #1
0
 /**
  * Return all markers and their values as associative array
  * @param Email $email
  * @return string[]
  */
 private function getMarkers(Email $email)
 {
     $markers = $email->getRecipientData();
     // Add predefined markers
     $markers['newsletter_view_url'] = $email->getViewUrl();
     $markers['newsletter_unsubscribe_url'] = $email->getUnsubscribeUrl();
     return $markers;
 }
Example #2
0
 /**
  * Creates the Message object from our current state and returns it
  *
  * @param Email $email
  * @return \TYPO3\CMS\Core\Mail\MailMessage
  */
 public function createMessage(Email $email)
 {
     /* @var $message \TYPO3\CMS\Core\Mail\MailMessage  */
     $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
     $message->setTo($email->getRecipientAddress())->setFrom([$this->senderEmail => $this->senderName])->setSubject($this->title);
     if ($this->replytoEmail) {
         $message->addReplyTo($this->replytoEmail, $this->replytoName);
     }
     $unsubscribeUrls = ['<' . $email->getUnsubscribeUrl() . '>'];
     if ($this->bounceAddress) {
         $message->setReturnPath($this->bounceAddress);
         array_unshift($unsubscribeUrls, '<mailto:' . $this->bounceAddress . '?subject=unsubscribe-' . $email->getAuthCode() . '>');
     }
     // Add header for easy unsubscribe, either by email, or standard URL
     $message->getHeaders()->addTextHeader('List-Unsubscribe', implode(', ', $unsubscribeUrls));
     $message->getHeaders()->addTextHeader('Precedence', 'bulk');
     foreach ($this->attachments as $attachment) {
         $message->attach($attachment);
     }
     // Specify message-id for bounce identification
     $msgId = $message->getHeaders()->get('Message-ID');
     $msgId->setId($email->getAuthCode() . '@' . $this->newsletter->getDomain());
     // Build plaintext
     $plain = $this->getPlain();
     $recipientData = $email->getRecipientData();
     if ($recipientData['plain_only']) {
         $message->setBody($plain, 'text/plain');
     } else {
         // Attach inline files and replace markers used for URL
         foreach ($this->attachmentsEmbedded as $marker => $attachment) {
             $embeddedSrc = $message->embed($attachment);
             $plain = str_replace($marker, $embeddedSrc, $plain);
             $this->html = str_replace($marker, $embeddedSrc, $this->html);
         }
         $message->setBody($this->html, 'text/html');
         $message->addPart($plain, 'text/plain');
     }
     return $message;
 }