Fix multipart email rendering #6378

* Refactored mail construction for different cases
* Added tests to verify the constructed email.message