protected function prepareMessageBody()
    {
        $attachments = $this->getSectionAttachments();
        if ($attachments) {
            $this->appendHeaderFields($this->contentInfoArray('multipart/mixed'));
            if (!empty($this->_text_plain) && !empty($this->_text_html)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('multipart/alternative')
                            . $this->getSectionMultipartAlternative()
                            . $attachments
                ;
            } elseif (!empty($this->_text_plain)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('text/plain')
                            . $this->getSectionTextPlain()
                            . $attachments
                ;
            } elseif (!empty($this->_text_html)) {
                $this->_body = $this->boundaryDelimiterLine('multipart/mixed')
                            . $this->contentInfoString('text/html')
                            . $this->getSectionTextHtml()
                            . $attachments
                ;
            } else {
                $this->_body = $attachments;
            }
            $this->_body .= $this->finalBoundaryDelimiterLine('multipart/mixed');
        } elseif (!empty($this->_text_plain) && !empty($this->_text_html)) {
            $this->appendHeaderFields($this->contentInfoArray('multipart/alternative'));
            $this->_body = $this->getSectionMultipartAlternative();
        } elseif (!empty($this->_text_plain)) {
            $this->appendHeaderFields($this->contentInfoArray('text/plain'));
            $this->_body = $this->getSectionTextPlain();
        } elseif (!empty($this->_text_html)) {
            $this->appendHeaderFields($this->contentInfoArray('text/html'));
            $this->_body = $this->getSectionTextHtml();
        } else {
            throw new EmailGatewayException(__('No attachments or body text was set. Can not send empty email.'));
        }
    }