transactionalEmailSettings = $transactionalEmailSettings; $this->smtpTransportZendV1 = $smtpTransportZendV1; $this->smtpTransportZendV2 = $smtpTransportZendV2; } /** * @param TransportInterface $subject * @param int $storeId * * @throws \ReflectionException * @throws \Zend_Mail_Transport_Exception */ public function send($subject, $storeId) { $message = $this->getMessage($subject); $this->sendMessage($message, $storeId); } /** * @param TransportInterface $subject * * @return Zend_Mail|\Magento\Framework\Mail\Message * @throws \ReflectionException */ private function getMessage($subject) { if (method_exists($subject, 'getMessage')) { $message = $subject->getMessage(); } else { $message = $this->useReflectionToGetMessage($subject); } return $message; } /** * @param Zend_Mail|\Magento\Framework\Mail\Message $message * @param int $storeId * * @throws \Zend_Mail_Transport_Exception */ private function sendMessage($message, $storeId) { if ($message instanceof \Zend_Mail) { $this->smtpTransportZendV1->send( $message, $storeId ); } else { $this->smtpTransportZendV2->send( Message::fromString($message->getRawMessage()), $storeId ); } } /** * @param TransportInterface $subject * * @return Zend_Mail * @throws \ReflectionException */ private function useReflectionToGetMessage($subject) { $reflection = new \ReflectionClass($subject); $property = $reflection->getProperty('_message'); $property->setAccessible(true); $message = $property->getValue($subject); return $message; } }