/** * Get the HTML part from the email. * * This is a current restriction since the BaseMessage class doesn't provide * method to get the rendered HTML. * * This only works in \yii\swiftmailer\Message. * * @param \yii\mail\BaseMessage $message * @return string|null the HTML string or null if not found. */ private static function getHtmlBody($message) { if ($message instanceof \yii\swiftmailer\Message) { $swiftMessage = $message->getSwiftMessage(); $r = new \ReflectionObject($swiftMessage); $parentClassThatHasBody = $r->getParentClass()->getParentClass()->getParentClass(); //\Swift_Mime_SimpleMimeEntity $body = $parentClassThatHasBody->getProperty('_immediateChildren'); $body->setAccessible(true); $children = $body->getValue($swiftMessage); foreach ($children as $child) { if ($child instanceof \Swift_MimePart && $child->getContentType() == 'text/html') { return $child->getBody(); } } } return null; }